forked from Parth-Vader/FB-Spider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.py
32 lines (24 loc) · 899 Bytes
/
graph.py
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
from facepy import GraphAPI
import json
from json2html import *
import webbrowser
graph= GraphAPI('YOUR_ACCESS_TOKEN')
print("Please enter the page-name:" )
PageName=raw_input()
search_res=graph.get('search?q='+PageName+'&type=page&limit=5')
for index,item in enumerate(search_res['data']):
#The 'data' key of 'search_res' dictionary is a list of dictionaries of 5 pages
print index+1,item['name']
pno=int(raw_input("Please enter the page no. : "))
pid=search_res['data'][pno-1]['id']
variable = graph.get(pid+'/posts?fields=comments.limit(5){message},message&limit=5')
with open('data.json', 'wb') as outfile:
json.dump(variable, outfile)
#infoFromJson = json.loads(variable)
table = json2html.convert(json = variable)
htmlfile=table.encode('utf-8')
#print(htmlfile)
f = open('Table.html','w')
f.write(htmlfile)
f.close()
webbrowser.open("Table.html")