Skip to content

Commit

Permalink
correcting for changes to the API
Browse files Browse the repository at this point in the history
correcting for several (currently undocumented) changes to the API
several attributes are no longer being returned by the project calls and two have been moved the runs calls
  • Loading branch information
DSAutomations committed Jun 24, 2018
1 parent 4426a89 commit 89473bc
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions ph2.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def getprojects(self):
jdata = json.loads(data)['projects']
# Convert nested JSON documents
for project_index in range(len(jdata)):
for field in ('options_json', 'templates_json'):
jdata[project_index][field] = json.loads(jdata[project_index][field])
jdata[project_index]['templates_json'] = json.loads(jdata[project_index]['templates_json'])
# Pass project details dictionaries to constructors, return array
return [PhProject(self, project) for project in jdata]

Expand Down Expand Up @@ -91,9 +90,6 @@ class PhProject(object):
templates_json The JSON-stringified representation of all the instructions for running this project. This
representation is not yet documented, but will eventually allow developers to create
plugins for ParseHub.
main_template The name of the template with which ParseHub should start executing the project.
main_site The default URL at which ParseHub should start running the project.
options_json An object containing several advanced options for the project.
last_run The run object of the most recently started run (orderd by start_time) for the project.
last_ready_run The run object of the most recent ready run (ordered by start_time) for the project. A ready run
is one whose data_ready attribute is truthy. The last_run and last_ready_run for a project may
Expand All @@ -102,15 +98,10 @@ class PhProject(object):
def __init__(self, ph, arg_dict: dict):
self.ph = ph
self.runs = []
self.main_site = arg_dict['main_site']
self.main_template = arg_dict['main_template']
self.options_json = arg_dict['options_json']
self.output_type = arg_dict['output_type']
self.syntax_version = arg_dict['syntax_version']
self.templates_json = arg_dict['templates_json']
self.title = arg_dict['title']
self.token = arg_dict['token']
self.webhook = arg_dict['webhook']
self.runs = self.get_runs(offset=0)
self.last_run = PhRun(self.ph, arg_dict['last_run']) if arg_dict['last_run'] else None
self.last_ready_run = PhRun(self.ph, arg_dict['last_ready_run']) if arg_dict['last_ready_run'] else None
Expand All @@ -126,6 +117,9 @@ def get_runs(self, offset: int=0):
'GET', self.ph.URLS['project'].format(self.token), dict(api_key=self.ph.api_key, offset=offset))
data = resp.data.decode('utf-8')
jdata = json.loads(data)['run_list']
# Convert nested JSON documents
for run_index in range(len(jdata)):
jdata[run_index]['options_json'] = json.loads(jdata[run_index]['options_json'])
return [PhRun(self.ph, rundata) for rundata in jdata]

def run(self, args: dict={}):
Expand Down Expand Up @@ -189,20 +183,23 @@ class PhRun(object):
md5sum The md5sum of the results. This can be used to check if result data has changed between two runs.
start_url The url that this run was started on.
start_value The starting value of the global scope for this run.
options_json An object containing several advanced options for the project.
"""
def __init__(self, ph, arg_dict: dict):
self.ph = ph
self.data = None
self.data_ready = arg_dict['data_ready']
self.end_time = arg_dict['end_time']
self.md5sum = arg_dict['md5sum']
self.options_json = arg_dict['options_json']
self.pages = arg_dict['pages']
self.project_token = arg_dict['project_token']
self.run_token = arg_dict['run_token']
self.start_time = arg_dict['start_time']
self.start_url = arg_dict['start_url']
self.start_value = arg_dict['start_value']
self.status = arg_dict['status']
self.webhook = arg_dict['webhook']
# Uncomment to fetch data for each run at initialization
# if self.data_ready:
# self.data = self.get_data()
Expand Down

0 comments on commit 89473bc

Please sign in to comment.