-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth.py
27 lines (19 loc) · 978 Bytes
/
oauth.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
import json
from apiclient import get_access_token;
def replace_token(position):
with open('appsconfig.json', 'r') as reddit_keys_file:
app = json.loads(reddit_keys_file.read())['apps'][position]
token = get_access_token(app['client_id'], app['client_secret'], app['user_agent'])
with open('tokens.txt', 'r') as token_file_read:
lines = token_file_read.read().splitlines()
lines[position] = token
with open('tokens.txt', 'w') as token_file_write:
token_file_write.write('\n'.join(lines))
def main():
with open('appsconfig.json', 'r') as reddit_keys_file:
keys = json.loads(reddit_keys_file.read())['apps']
tokens = [get_access_token(app['client_id'], app['client_secret'], app['user_agent']) for app in keys]
with open('tokens.txt', 'w') as token_file:
token_file.write('\n'.join(tokens))
if __name__ == "__main__":
main()