-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
executable file
·86 lines (62 loc) · 2.03 KB
/
Copy pathexample.py
File metadata and controls
executable file
·86 lines (62 loc) · 2.03 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
79
80
81
82
83
84
85
#!/usr/bin/env python
import json, codecs
print('This is an example python script.')
print('Modify as desired, or set the manifest "command" key to something else entirely.')
invocation = json.loads(open('config.json').read())
config = invocation['config']
inputs = invocation['inputs']
destination = invocation['destination']
# Display everything provided to the job
def display(section):
print(json.dumps(section, indent=4, sort_keys=True))
print('\nConfig:')
display(config)
print('\nDestination:')
display(destination)
print('\nInputs:')
display(inputs)
# Check if the flywheel SDK is installed
try:
import flywheel
# Make some simple calls to the API
fw = flywheel.Flywheel(inputs['api-key']['key'])
user = fw.get_current_user()
config = fw.get_config()
print('You are logged in as ' + user.firstname + ' ' + user.lastname + ' at ' + config.site.api_url[:-4])
except ImportError:
print('\nFlywheel SDK is not installed, try "fw gear modify" and then "pip install flywheel-sdk".\n')
# Check if requests is installed
try:
import requests
# Find out how many people are in space \o/
r = requests.get(
'https://www.howmanypeopleareinspacerightnow.com/peopleinspace.json',
headers={
'Host': 'www.howmanypeopleareinspacerightnow.com',
'User-Agent': 'curl/7.47.0',
'Accept': '*/*',
},
)
# Save astronaut data as metadata
if r.ok:
data = r.json()
astronauts = data['people']
print("There are " + str(len(astronauts)) + " in space today:")
for astronaut in astronauts:
print("\t" + astronaut['name'])
metadata = {
'session' : {
'info': {
'astronauts': astronauts
}
}
}
with open('output/.metadata.json', 'wb') as f:
json.dump(metadata, codecs.getwriter('utf-8')(f), ensure_ascii=False)
else:
# Might be that the API is down today. Check to see if we still have a space program?
print('Not sure how many people are in space :(')
print()
print(r.text)
except ImportError:
print('\nRequests is not installed, try "fw gear modify" and then "pip install requests".\n')