Created
July 20, 2018 10:02
-
-
Save rienafairefr/c380034365903e7805b06f891d52e4f9 to your computer and use it in GitHub Desktop.
This file contains 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
from datetime import date | |
import time | |
import requests | |
oar_url = 'http://srvoar.master.iot-lab.info' | |
date_from = date(2018, 6, 1) | |
site = 'euratech' | |
timestamp_from = time.mktime(date_from.timetuple()) | |
headers = {"Content-Type": "application/json"} | |
memo = {} | |
def req(url, parameters=None): | |
if parameters is None: | |
parameters = {'limit': 100, 'state': 'Terminated', 'from': timestamp_from} | |
if url not in memo: | |
memo[url] = requests.get(oar_url + url, params=parameters, headers=headers).json() | |
return memo[url] | |
jobs = req('/oarapi/jobs') | |
while True: | |
for job in jobs['items']: | |
found = False | |
job_resources = None | |
for link in job['links']: | |
if link.get('title') != 'resources': continue | |
job_resources = link['href'] | |
break | |
if not job_resources: continue | |
resources = req(link['href'])['items'] | |
for resource in resources: | |
resource_details = None | |
for link in resource['links']: | |
if link.get('rel') != 'self': continue | |
resource_details = link['href'] | |
break | |
if not resource_details: continue | |
resource_detail = req(resource_details) | |
if resource_detail.get('site') == site: | |
found = True | |
break | |
if found: | |
print(str(job['id']) + ' ' + job['owner']) | |
next_jobs = None | |
for link in jobs['links']: | |
if link.get('rel') == 'next': | |
next_jobs = link['href'] | |
break | |
if not next_jobs: break | |
jobs = req(next_jobs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment