Created
July 17, 2013 09:19
-
-
Save luke/6019064 to your computer and use it in GitHub Desktop.
Quick and dirty script to check status of last 100 jobs on picloud.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| import requests | |
| import lxml.html | |
| import collections | |
| def picloud_health_check(username, password): | |
| # setup session | |
| session = requests.Session() | |
| session.verify = False | |
| # get the login page | |
| resp = session.get('https://www.picloud.com/accounts/login/') | |
| # grab the csrf token | |
| # <input type='hidden' name='csrfmiddlewaretoken' value='....' /> | |
| csrfmiddlewaretoken = resp.text.split("csrfmiddlewaretoken' value='")[1].split("'")[0] | |
| logging.info("token: %s" % csrfmiddlewaretoken) | |
| # login | |
| resp = session.post('https://www.picloud.com/accounts/login/', headers=dict(Referer=resp.url), data=dict( | |
| username = username, | |
| password = password, | |
| next = '/accounts/', | |
| csrfmiddlewaretoken = csrfmiddlewaretoken)) | |
| # try to grab the latest 100 jobs | |
| resp = session.post('https://www.picloud.com/accounts/jobs/search/', data=dict( | |
| num_results=100, | |
| page_num=1, | |
| collapse=True, | |
| timezone=4, | |
| postid=2)) | |
| # count the different statuses and return as dict | |
| doc = lxml.html.fromstring(resp.text.encode("UTF-8")) | |
| statuses = [x.text_content() for x in doc.xpath('//job/status')] | |
| status_counts = dict(collections.Counter(statuses).most_common()) | |
| return status_counts | |
| if __name__ == '__main__': | |
| logging.basicConfig(level=logging.DEBUG) | |
| print repr(picloud_health_check('[email protected]','password')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment