-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcom-rtd.py
More file actions
executable file
·78 lines (60 loc) · 2.06 KB
/
com-rtd.py
File metadata and controls
executable file
·78 lines (60 loc) · 2.06 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
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python
import os
import sys
import datetime
import requests
from pyquery import PyQuery
from dateutil.parser import parse
HOST = 'https://readthedocs.com'
SLUG = 'read-the-docs-time-test'
USER = 'time-test'
PASS = 'time-test'
def login(url, session):
# Retrieve the CSRF token first
session.get(url) # sets cookie
csrftoken = session.cookies['csrftoken']
login_data = dict(login=USER, password=PASS, csrfmiddlewaretoken=csrftoken, next='/')
session.post(url, data=login_data, headers=dict(Referer=url))
return session
passing = True
with open('time.rst', 'w') as time_file:
time_file.write('Time\n====\n\n')
time_file.write('%s' % datetime.datetime.now())
os.system('git commit -am Time && git push origin master')
with requests.Session() as session:
login_resp = login('{host}/accounts/login/'.format(host=HOST), session)
print("Current Time: %s " % datetime.datetime.now())
api_resp = session.get(
'{host}/api/v1/build/?project__slug={slug}&format=json&limit=1&type=html'.format(host=HOST, slug=SLUG),
)
url = '{host}/docs/{slug}/en/latest/time.html'.format(host=HOST, slug=SLUG)
print(url)
html_resp = session.get(url)
five_minutes_ago = datetime.datetime.now() - datetime.timedelta(minutes=5)
# try:
# # API tests
# obj = api_resp.json()['objects'][0]
# if not obj['success']:
# print "Build Failed"
# passing = False
# if five_minutes_ago > parse(obj['date']):
# print "API Build Old"
# passing = False
# except:
# import traceback
# traceback.print_exc()
# passing = False
# HTML tests
pyq = PyQuery(html_resp.content)
page_time = ' '.join(pyq('#time').text().split(' ')[-2:])
print("On Page Time: %s" % page_time)
if page_time and five_minutes_ago > parse(page_time):
print("Time on page is Old: %s" % page_time)
passing = False
# Final bits
if passing:
print("OK")
#sys.exit(0)
else:
print("FAIL")
#sys.exit(2)