Skip to content

Commit

Permalink
0.0309
Browse files Browse the repository at this point in the history
  • Loading branch information
justinzm committed Mar 9, 2021
1 parent 24fe9be commit 93f4135
Show file tree
Hide file tree
Showing 23 changed files with 2,338 additions and 730 deletions.
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Pipfile.lock
build/
dist/
.idea/*
.idea/
gopup.egg-info/*
.idea/workspace.xml
gopup/__pycache__
Expand All @@ -15,14 +16,10 @@ gopup/index/__pycache__/*

.idea/inspectionProfiles/Project_Default.xml
.idea/workspace.xml
gopup/economic/__pycache__/*
gopup/event/__pycache__/*
gopup/economic/*
gopup/economic/
venv/*
*.pyc
*.pyc
.idea/gopup.iml
.idea/workspace.xml
gopup/event/__pycache__/cons.cpython-37.pyc
gopup/event/__pycache__/area_baidu.cpython-37.pyc
gopup/event/__pycache__/__init__.cpython-37.pyc
.idea/workspace.xml
552 changes: 322 additions & 230 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified gopup/event/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified gopup/event/__pycache__/area_baidu.cpython-37.pyc
Binary file not shown.
Binary file modified gopup/event/__pycache__/cons.cpython-37.pyc
Binary file not shown.
106 changes: 56 additions & 50 deletions gopup/event/area_baidu.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,34 @@ def migration_area_baidu(area="武汉市", indicator="move_in", date="20200201")
:return: 迁入地详情/迁出地详情的前50个
:rtype: pandas.DataFrame
"""
if area == "全国":
payload = {
"dt": "country",
"id": 0,
"type": indicator,
"date": date,
}
else:
city_dict.update(province_dict)
inner_dict = dict(zip(city_dict.values(), city_dict.keys()))
if inner_dict[area] in province_dict.keys():
dt_flag = "province"
try:
if area == "全国":
payload = {
"dt": "country",
"id": 0,
"type": indicator,
"date": date,
}
else:
dt_flag = "city"
payload = {
"dt": dt_flag,
"id": inner_dict[area],
"type": indicator,
"date": date,
}
city_dict.update(province_dict)
inner_dict = dict(zip(city_dict.values(), city_dict.keys()))
if inner_dict[area] in province_dict.keys():
dt_flag = "province"
else:
dt_flag = "city"
payload = {
"dt": dt_flag,
"id": inner_dict[area],
"type": indicator,
"date": date,
}

url = "https://huiyan.baidu.com/migration/cityrank.jsonp"
r = requests.get(url, params=payload)
json_data = json.loads(r.text[r.text.find("({") + 1 : r.text.rfind(");")])
return pd.DataFrame(json_data["data"]["list"])
url = "https://huiyan.baidu.com/migration/cityrank.jsonp"
r = requests.get(url, params=payload)
json_data = json.loads(r.text[r.text.find("({") + 1 : r.text.rfind(");")])
return pd.DataFrame(json_data["data"]["list"])
except:
return None


def migration_scale_baidu(area="武汉市", indicator="move_out", date="20210112"):
Expand All @@ -70,37 +73,40 @@ def migration_scale_baidu(area="武汉市", indicator="move_out", date="20210112
:return: 时间序列的迁徙规模指数
:rtype: pandas.DataFrame
"""
if area == "全国":
payload = {
"dt": "country",
"id": 0,
"type": indicator,
"date": date
}
else:
city_dict.update(province_dict)
inner_dict = dict(zip(city_dict.values(), city_dict.keys()))
try:
if inner_dict[area] in province_dict.keys():
dt_flag = "province"
else:
dt_flag = "city"

try:
if area == "全国":
payload = {
"dt": dt_flag,
"id": inner_dict[area],
"dt": "country",
"id": 0,
"type": indicator,
"date": date
}
except Exception as e:
return "省份 或者 具体城市名 错误"
url = "https://huiyan.baidu.com/migration/historycurve.jsonp"
r = requests.get(url, params=payload)
json_data = json.loads(r.text[r.text.find("({") + 1 : r.text.rfind(");")])
temp_df = pd.DataFrame.from_dict(json_data["data"]["list"], orient="index")
temp_df.index = pd.to_datetime(temp_df.index)
temp_df.columns = ["迁徙规模指数"]
return temp_df
else:
city_dict.update(province_dict)
inner_dict = dict(zip(city_dict.values(), city_dict.keys()))
try:
if inner_dict[area] in province_dict.keys():
dt_flag = "province"
else:
dt_flag = "city"

payload = {
"dt": dt_flag,
"id": inner_dict[area],
"type": indicator,
"date": date
}
except Exception as e:
return "省份 或者 具体城市名 错误"
url = "https://huiyan.baidu.com/migration/historycurve.jsonp"
r = requests.get(url, params=payload)
json_data = json.loads(r.text[r.text.find("({") + 1 : r.text.rfind(");")])
temp_df = pd.DataFrame.from_dict(json_data["data"]["list"], orient="index")
temp_df.index = pd.to_datetime(temp_df.index)
temp_df.columns = ["迁徙规模指数"]
return temp_df
except:
return None


if __name__ == "__main__":
Expand Down
15 changes: 9 additions & 6 deletions gopup/event/history_daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ def history_daily():
DataFrame
"year,title, type, link, desc""
"""
url = "https://www.bjsoubang.com/api/getHistoryDaily"
r = requests.get(url=url)
res_list = json.loads(r.text)['info']
df = pd.DataFrame(res_list)
df = df.drop(['cover', 'festival', 'recommend'], axis=1)
return df
try:
url = "https://www.bjsoubang.com/api/getHistoryDaily"
r = requests.get(url=url)
res_list = json.loads(r.text)['info']
df = pd.DataFrame(res_list)
df = df.drop(['cover', 'festival', 'recommend'], axis=1)
return df
except:
return None


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 93f4135

Please sign in to comment.