-
Notifications
You must be signed in to change notification settings - Fork 1
/
jarvis
executable file
·72 lines (52 loc) · 1.73 KB
/
jarvis
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
66
67
68
69
70
71
72
#!/usr/bin/python
from PyPDF2 import PdfFileWriter, PdfFileReader
from os.path import basename
import webbrowser
import os
import sys
import shutil
def seperate_pdf(file):
print("Seperating pdf command triggered")
print("Initializing new directory...")
parent = os.getcwd()
directory = "pdf-output"
path = os.path.join(parent, directory)
if os.path.exists(path):
print("Directory '{}' already exists, deleting..".format(directory))
shutil.rmtree(path)
os.mkdir(path)
print("Directory '{}' created".format(directory))
filename = file[:-4]
print("Seperating {}...".format(file))
input = PdfFileReader(open(file, "rb"))
for i in range(input.numPages):
output = PdfFileWriter()
output.addPage(input.getPage(i))
with open("{}/{}-p{}.pdf".format(path, filename, i), "wb") as outputStream:
output.write(outputStream)
print("Done.")
def pdf(arguments):
action = arguments[0]
if action == "split":
if len(arguments) != 2:
raise Exception(
"Invalid arguments. Usage: jarvis pdf split [filename.pdf]")
seperate_pdf(arguments[1])
else:
raise Exception("Invalid command. Possible commands: jarvis pdf split")
def github(arguments):
action = arguments[0]
if action == "open":
print("In progress")
parent = basename(os.getcwd())
webbrowser.open("http://github.com/Angela-UW/{}".format(parent))
if __name__ == "__main__":
num_args = len(sys.argv)
# Get command
command = sys.argv[1]
if command == "pdf":
pdf(sys.argv[2:])
elif command == "git":
github(sys.argv[2:])
else:
print("Invalid command. Please try again")