-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
40 lines (30 loc) · 973 Bytes
/
Copy pathapi.py
File metadata and controls
40 lines (30 loc) · 973 Bytes
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
'''
The module is for retrieving json file from Twitter API.
'''
import requests
def api_file_retriever(appendix: str, user_name: str):
'''
Returns a dictionary of a json file from Twitter API
using given user name and resource url ending.
>>> len(list(api_file_retriever('friends/list.json', '@BarackObama').items()))
6
'''
base_url = 'https://api.twitter.com/'
access_token = '''AAAAAAAAAAAAAAAAAAAAAJmp\
MwEAAAAAzOMPOTJlHaJF880r\
Ufgj%2BClXFAQ%3Do16zw9su\
1B7UKGYLyM6homsX4WSHP63Y\
ZzsGOarKNcDiRVTw8u'''
search_headers = {
'Authorization':'Bearer {}'.format(access_token)
}
search_params = {
'screen_name': user_name,
}
search_url = '{0}1.1/{1}'.format(base_url, appendix)
response = requests.get(search_url, headers=search_headers, params=search_params)
json_response = response.json()
return json_response
if __name__ == '__main__':
import doctest
doctest.testmod()