-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetFeed.py
More file actions
36 lines (27 loc) · 1.4 KB
/
getFeed.py
File metadata and controls
36 lines (27 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import requests
import json
import datetime
import pandas as pd
from dateutil.parser import parse
def handleDate(x):
if isinstance(x, datetime.date):
return "{}-{}-{}".format(x.year, x.month, x.day)
token = 'EAACEdEose0cBADNqQCOerYjMBsE5iiUp79vrqnh3FhoYWZAPmaZBfdsuZCi43IpZBsC7S2xICxNQunP2nZB2ENrMqM5r4KyZBA7Km1fLxzvrIvNUUE9KZCdhzwS2lf2ZCRUYBT3GhfirlGa3W0zASZC7tOUkZBpGpx1ENQSdbYZC2NeswAEsjKeZAGIM'
group = {'689157281218904':'台北技能交換'}
feeds = []
for ele in group:
res = requests.get('https://graph.facebook.com/v2.9/{}/feed?limit=100&access_token={}'.format(ele, token))
while 'paging' in res.json():
for information in res.json()['data']:
if 'message' in information:
feeds.append([group[ele], information['message'], parse(information['updated_time']).date(), information['id']])
res = requests.get(res.json()['paging']['next'])
# print(json.dumps(feeds, indent=4, separators=(',', ': '), ensure_ascii=False, default = handleDate))
with open('feeds.json', 'w') as outfile:
json.dump(feeds, outfile, indent=4, separators=(',', ': '), ensure_ascii=False, default = handleDate)
#最後將list轉換成dataframe,並輸出成csv檔
#
# information_df = pd.DataFrame(feeds, columns=['粉絲專頁', '發文內容', '發文時間'])
# information_df.to_csv('Data Visualization Information.csv', index=False)