-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.py
More file actions
90 lines (77 loc) · 2.32 KB
/
api.py
File metadata and controls
90 lines (77 loc) · 2.32 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
80
81
82
83
84
85
86
87
88
89
90
# api.py
# @author: Fred Lee
# Intended for BIDS purposes
import api
import time
import json
# import facebook
import requests
from datetime import datetime
import API_KEY as API_KEY
class fbAPI(object):
def __init__(self, link):
start = link.find('facebook.com/') + 13
if start == -1:
self.page = None
print 'Not a valid address'
return
if link[start:].find('/') == -1:
end = 5
else:
end = link[start:].find('/') + start
self.page = link[start:end]
if self.page == 'media':
print 'Not a page'
return
self.response = requests.get(
API_KEY.URL.format(
version=API_KEY.fb_version,
page=self.page,
KEY=API_KEY.facebook)
).json()
if 'error' in self.response:
print 'Failed to fetch'
def point(self):
if 'error' in self.response or self.page == 'media' or self.page == None:
return
point = 0
if self.post_date_diff() != None and self.post_date_diff() < 3.154e+7:
point += 1
if self.website() != None:
point += 1
if self.email() != None:
point += 1
if self.description() != None:
point += 1
if self.about() != None:
point += 1
return point
def post_date_diff(self):
if self.page == None:
return None
date = datetime.strptime(self.response['posts']['data'][0]['created_time'], '%Y-%m-%dT%H:%M:%S+0000')
return (datetime.today() - date).total_seconds()
def website(self):
if 'website' in self.response:
return self.response['website']
return None
def email(self):
if 'emails' in self.response:
return self.response['emails'][0]
return None
def description(self):
if 'description' in self.response:
return self.response['description']
return None
def about(self):
if 'about' in self.response:
return self.response['about']
return None
def id(self):
return self.response['id']
# class twitterAPI(object):
# def __init__(self, link):
# start = link.find('twitter.com/') + 12
# end = link[start:].find('/') + start
# self.page = link[start:end]
# curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'count=1&screen_name=freshy_freddy' --header 'Authorization: OAuth oauth_consumer_key="TvpN2t3xLm1mHlzYUpHtGzN4n", oauth_nonce="0e5bc766548a941a8e3390621d63e1ee", oauth_signature="wbqugutxmpPOLq%2BgTwmQpv4rKPA%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1459930228", oauth_version="1.0"'