-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker.py
79 lines (70 loc) · 2.42 KB
/
tracker.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
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
73
74
75
76
77
78
79
#import PyZenity
import subprocess, os
from threading import Thread
import re
login=""
password=""
currentcourse=""
def getvariables():
global login,password,currentcourse
with open('login.txt', 'r') as f:
login = f.readline().split("\n")[0]
print login
with open('password.txt', 'r') as f:
password = f.readline().split("\n")[0]
print password
with open('currentcourse.txt', 'r') as f:
currentcourse = f.readline().split("\n")[0]
def Run(command):
proc=subprocess.Popen(command,bufsize=1,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True)
return proc
def Trace(proc):
global currentcourse
while proc.poll() is None:
line=proc.stdout.readline()
if line:
print "Readline", line
m=re.search('] (.+?)% ',line)
message=re.search("Downloading ",line)
#httpsmessage=re.search("Starting new HTTPS connection",line)
loggedin=re.search("Logged in on accounts.coursera.org",line)
if m:
found=m.group(1)
print "I found this ",found
found=int(found)
found=float(found)
print found
proczenity.stdin.write("{0}\n".format(found))
#if httpsmessage:
# proczenity.stdin.write("# Starting new HTTPS connection\n")
if loggedin:
proczenity.stdin.write("# Logged in on accounts.coursera.org\n")
if message:
if re.search(currentcourse,line):
totalmessage=""
message=line.split(currentcourse)
message=message[-1]
print message
message=message.split("/")
print "messagesplitted", message
message=message[-1]
message=message.split("\n")[0]
message="[ "+message[:50]+"...]"
proczenity.stdin.write("# Downloading...{0}\n".format(message))
else:
proczenity.stdin.write("# {0}\n".format(line))
os.kill(proczenity.pid, signal.SIGTERM) #not sure if it works, so second salve behind...
time.sleep(5)
proczenity.terminate() #maybe overkill ?
getvariables()
#command for the OpenPandora
command=["python","coursera-dl","""--path=COURSES""","-u",login,"-p",password,currentcourse]
#print command
#cmd = 'zenity --width=500 --height=100 --progress --text="Downloading course... Authenticating..."'
#position for the Open Pandora
cmd = './yad --title="Courserian" --geometry=700x65+50+375 --width=700 --height=65 --progress --image="coursera-progress2.png" --image-on-top --no-buttons --window-icon=icon.png'
proczenity = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
proc=Run(command)
Trace(proc)