-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.py
executable file
·44 lines (36 loc) · 1.23 KB
/
get.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python3
import sys
import pyquery
import lib
OPTS = ("text", "input",)
def print_input(session, day, opt):
if opt == "text":
req = session.get("https://adventofcode.com/%d/day/%d" % (lib.current_year(), day))
query = pyquery.PyQuery(req.content)
parts = query('article.day-desc')
for i, part in enumerate(parts):
print(">>>>>>>>>>>>>>>>>> Part %d <<<<<<<<<<<<<<<<<" % (i + 1))
text = part.text_content()
print(text)
elif opt == "input":
# seems to be one input for all parts
req = session.get("https://adventofcode.com/%d/day/%d/input" % (lib.current_year(), day))
text = req.content.decode('utf8').rstrip('\n')
print(text)
def usage():
print("Usage: {" + ','.join(OPTS) + "} <day>", file=sys.stderr)
print("day must be in range [1..25]", file=sys.stderr)
def main():
if len(sys.argv) == 3:
opt = sys.argv[1].lower()
day = int(sys.argv[2])
if not (opt in OPTS and 1 <= day <= 25):
usage()
else:
session = lib.restore_session()
if session:
print_input(session, day, opt)
else:
usage()
if __name__ == "__main__":
main()