-
Notifications
You must be signed in to change notification settings - Fork 7
/
get_filter_fritz.py
47 lines (35 loc) · 1.25 KB
/
get_filter_fritz.py
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
# Author: Igor Andreoni
# email: [email protected]
import os
import requests
# Copy the API token from your Fritz account
token = 'copied-from-fritz'
token = os.environ.get('FRITZ_TOKEN')
def api(method, endpoint, data=None):
"""API request"""
headers = {'Authorization': f'token {token}'}
response = requests.request(method, endpoint, json=data, headers=headers)
return response
def getFilter(filter_id):
"""GET a filter"""
response = api('GET',
f'https://fritz.science/api/filters/{filter_id}'
)
if response.status_code == 200:
filt = response.json()['data']
else:
print(f'HTTP code: {response.status_code}, {response.reason}')
return filt
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='Get filters from Fritz.')
parser.add_argument('filter_id', nargs='+', help='Filter IDs, space \
separated')
parser.add_argument('--group', '-g', dest='group_id', default=1544,
type=int, help='Group ID')
args = parser.parse_args()
# Fix the filter IDs
filter_ids = [int(x) for x in args.filter_id]
for filter_id in filter_ids:
filt = getFilter(filter_id)
print(filt)