-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFB-API.py
More file actions
79 lines (60 loc) · 1.9 KB
/
FB-API.py
File metadata and controls
79 lines (60 loc) · 1.9 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import requests
import json
import jieba
import operator
import pandas as pd
# wd = pd.DataFrame([[]])
# wd.append({},ignore_index=True)
# print(wd)
token = "EABKk1WPoWjsBAJalwXBuG7z5XoxSmIhWNKgNKYbJP2bQQ7W8QaYPwVw3fP7aLiNL3Dxrj2p6krgkZC521eVJbaACX6srcR19TduKC5cSEJ9TGtpBsIQIZCGOmGhyUZA9rdK29sM5UCtN8BlYyYoizMqfym8GPXvwe0fZCyIRh6XinDAW1uGI3kKZCjGZC13cl70F4NEBcDRd9Ig144moW4BMFJhmUH6lhR0BJRmhQQ5FdMnKwR1zZCH"
res = requests.get("https://graph.facebook.com/v13.0/me/posts?access_token=" + token)
jd = json.loads(res.text)
word = []
while "paging" in jd:
for post in jd["data"]:
if "message" in post:
word += jieba.cut(post["message"])
res = requests.get(jd["paging"]["next"])
jd = json.loads(res.text)
dic_w = {}
for ele in word:
if ele not in dic_w:
dic_w[ele] = 1
else:
dic_w[ele] +=1
sort_w = sorted(dic_w.items(),key=operator.itemgetter(1),reverse=True)
no_word = [".",",","!","~","。"," ","(",")","[","]","/","6996669999999969999999966699666666699"]
dic_sort = {}
for ele in sort_w:
dic_sort[ele[0]]=ele[1]
for w in no_word:
for x in dic_sort:
if w in x :
dic_sort[x]=0
print(dic_sort)
# for w in no_word:
# for ele in sort_w:
# if w in ele[0]:
# dic_sort[ele[0]] = 0
# else:
# for x in no_word:
# if x not in ele[0]:
# dic_sort[ele[0]] = sort_w[1]
# for ele in dic_sort:
# if len(ele[0])>= 3 or ele[1]>8:
# print(ele[0],ele[1])
wd = pd.DataFrame([[None,None]])
wd.columns=["word","count"]
nd = wd
for ele in dic_sort:
if len(ele)>=3:
nd = nd.append({"word":ele,"count":dic_sort[ele]},ignore_index=True)
print(nd)
dic_w={"word":[],"count":[]}
for ele in word:
if ele not in dic_w["word"]:
dic_w["word"].append(ele)
dic_w["count"].append(1)
else:
dic_w["count"][dic_w["word"].index(ele)]+=1
print(dic_w)