-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcrawler.py
executable file
·69 lines (52 loc) · 1.67 KB
/
crawler.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
import urllib
import urllib2
import requests
import os
import json
import smtplib
import email.MIMEMultipart
import email.MIMEText
print "Hello World!"
url = "https://leetcode.com/problemset/algorithms/"
url2 = "https://leetcode.com/api/problems/algorithms/"
response = urllib2.urlopen(url2)
data = json.load(response)
print data
print data['category_slug']
# print json.dumps(data, sort_keys=True, indent=4)
total = data['num_total']
print 'num_total is: ', total
Leetcode_count_file = "/tmp/leetcode_cnt.txt"
f = open(Leetcode_count_file, 'r')
previous_count = f.readline()
previous_count = int(previous_count)
print "previous_count is: "
print previous_count
if previous_count != total:
print "previous_count != total"
os.remove(Leetcode_count_file)
print "old file removed"
f = open(Leetcode_count_file, 'w')
f.write(str(total))
fromaddr = XXXX
fromaddrPassword = YYYY
toaddr = ZZZZ
# server = smtplib.SMTP('smtp.gmail.com', 587)
server = smtplib.SMTP_SSL('smtp.gmail.com:465')
# server.ehlo()#this line is not needed! If uncommented, it'll throw exception!
# server.starttls()#this line is not needed! If uncommented, it'll throw exception!
# server.login("[email protected]", "Betrieber304")
server.login(fromaddr, fromaddrPassword)#I've enabled less secure apps for this account, so it might now work on other accounts
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Leetcode has new questions!"
body = "Previous/Now: "
body += str(previous_count)
body += '/'
body += str(total)
msg.attach(MIMEText(body, 'plain'))
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
print "It reached the end!"