This repository was archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (51 loc) · 2.25 KB
/
main.py
File metadata and controls
65 lines (51 loc) · 2.25 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
"""
HackerRank.com scrape
Joshua Lindsay (jlindsay90@gmail.com)
Sign into HackerRank and archive solutions in a git repository (where they should be)
"""
import configparser
from argparse import ArgumentParser
from hackerrankops import HRClient, mergeModels, sortModels
import fileops as IO
import os
import better_exceptions
# TODO store the session id, cookie, token in variables?
def getArgs():
parser = ArgumentParser(description='Export your code from HackerRank.com!')
parser.add_argument('-u', '--username', action='store', default=os.environ.get('HR_USER'), help='HR username')
parser.add_argument('-p', '--password', action='store', default=os.environ.get('HR_PASS'), help='HR password')
parser.add_argument('-f', '--file', action='store', default=os.environ.get('HR_FILE'), help='load/create file')
parser.add_argument('-d', '--dir', action='store', default=os.environ.get('HR_REPO'), help='repository path')
parser.add_argument('--html', action='store_true', help='write contest and challenge html')
#parser.add_argument('-r', '--repo', action='store', metavar='repo', help='remote git repository')
return parser.parse_args();
def main():
args = getArgs()
# TODO try to create git repository if json file and repo provided
if not args.username or not args.password:
print('username or password not provided. exiting.')
return
filePath = IO.getFullPath(args.file)
archivePath = IO.getFullPath(args.dir)
models = IO.load(filePath)
user = None
newModels = None
# try to login and fetch new models
# TODO return a partial set of models upon failure
with HRClient(args.username, args.password) as hrankclient:
user = hrankclient.getUserModel()
newModels = hrankclient.getNewModels(models)
if not newModels:
print('no new submissions. exiting.')
return
# TODO log which submissions are new, different, updated?
allModels = mergeModels(models, newModels)
# TODO check if files match?
if filePath:
IO.dump(filePath, allModels)
# TODO do not overwrite files?
if archivePath:
IO.initializeDir(archivePath, user, args.dir)
sortedModels = sortModels(newModels)
IO.writeModels(sortedModels, args.html)
main()