-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_user.py
More file actions
54 lines (43 loc) · 1.74 KB
/
create_user.py
File metadata and controls
54 lines (43 loc) · 1.74 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
# creates a new user
import rsaved
import sys, re, json, time, os
__version__ = rsaved.__version__
if __name__ == "__main__":
print(f'rsaved/{__version__} create_user.py')
if len(sys.argv) == 2:
feed_url = sys.argv[1]
elif len(sys.argv) > 2:
print('Usage:', sys.argv[0], '[JSON feed URL]')
print('Feed URL can be found at https://www.reddit.com/prefs/feeds/')
sys.exit(1)
else:
print('Feed URL can be found at https://www.reddit.com/prefs/feeds/')
feed_url = input('Enter the feed URL: ')
if not re.fullmatch('^https?:\/\/www\.reddit\.com\/saved\.json\?feed=[a-z0-9]+&user=[A-Za-z0-9_-]+$', feed_url):
print('Feed URL invalid?')
sys.exit(2)
feed_id = feed_url.split('feed=')[1].split('&')[0]
username = feed_url.split('=')[-1]
print('----------' + '-'*len(feed_id))
print('Feed ID: ', feed_id)
print('Username:', username)
if os.path.exists(f'user/{username}'):
print('This user already exists!')
sys.exit(3)
print(f'Creating folders for {username}...')
os.mkdir(f'user/{username}')
os.mkdir(f'user/{username}/cache')
os.mkdir(f'user/{username}/cache/history')
os.mkdir(f'user/{username}/cache/download_user')
os.mkdir(f'user/{username}/library')
os.mkdir(f'user/{username}/reddit')
print('Copying config files...')
with open('config_default.json','r') as f: config_default = json.load(f)
with open('rsaved_default.json','r') as f: rsaved_default = json.load(f)
rsaved_default["username"] = username
rsaved_default["feed_id"] = feed_id
rsaved_default["created"] = int(time.time())
rsaved_default["version"] = __version__
with open(f'user/{username}/rsaved.json','w') as f: json.dump(rsaved_default, f, indent=4)
with open(f'user/{username}/config.json','w') as f: json.dump(config_default, f, indent=4)
print('Done!')