This repository has been archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.sh
executable file
·52 lines (39 loc) · 1.54 KB
/
api.sh
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
#!/usr/bin/env python
import requests
import json
import os
FRESHDESK_API_KEY = os.getenv('FRESHDESK_API_KEY')
def api(url):
cache_dir = 'api_cache/{}'.format(url)
cache_path = '{}/response.json'.format(cache_dir)
if not os.path.exists(cache_dir):
_dirbase = ""
for dd in cache_dir.split('/'):
_dirbase = os.path.join(_dirbase, dd)
try:
os.mkdir(_dirbase)
except Exception as e:
pass
if os.path.exists(cache_path):
with open(cache_path, 'r') as cache_f:
return json.load(cache_f)
r = requests.get('https://picovico.freshdesk.com/api/v2/{}'.format(url), auth=(FRESHDESK_API_KEY, 'X'))
with open(cache_path, 'w') as cache_f:
cache_f.write(json.dumps(r.json()))
return r.json()
cats = api('solutions/categories')
for category in cats:
cat_name = category.get('name')
cat_id = category.get('id')
print "-- Fetching category {} {}".format(cat_name, cat_id)
folders = api('solutions/categories/{}/folders'.format(cat_id))
for folder in folders:
f_name = folder.get('name')
f_id = folder.get('id')
print "-- -- Fetching folder {} {}".format(f_name, f_id)
articles = api("solutions/folders/{}/articles".format(f_id))
for article in articles:
article_id = article.get('id')
question = article.get('title')
print "-- -- -- Fetching article {} {}".format(question, article_id)
faq = api("solutions/articles/{}".format(article_id))