Generate initial zasoby.csv file
This commit is contained in:
parent
1d8e18247d
commit
1b2ca8eb87
2 changed files with 31 additions and 6 deletions
17
discourse.py
17
discourse.py
|
|
@ -3,6 +3,7 @@ Class to generate a csv file based on data fetched via Discourse REST API
|
||||||
'''
|
'''
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
import csv
|
||||||
|
|
||||||
class Discourse():
|
class Discourse():
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
|
|
@ -20,13 +21,17 @@ class Discourse():
|
||||||
res_json = json.loads(res.text)
|
res_json = json.loads(res.text)
|
||||||
return res_json
|
return res_json
|
||||||
|
|
||||||
def get_category_topics(self, category_id: str) -> requests.Response:
|
def category_topics_csv(self, category_id: str) -> requests.Response:
|
||||||
"""Get topics from a Discourse category"""
|
"""Save category topics to a csv file"""
|
||||||
cat_data = self.get_category_data(category_id)
|
cat_data = self.get_category_data(category_id)
|
||||||
for topic in cat_data["topic_list"]["topics"]:
|
columns = ["id", "title", "tags", "url"]
|
||||||
print(f'{topic["id"]}, {topic["title"]}, {topic["tags"]}, {self.url}t/{topic["id"]}')
|
with open('zasoby.csv', 'w', encoding='UTF8') as f:
|
||||||
|
write = csv.writer(f)
|
||||||
|
write.writerow(columns)
|
||||||
|
for topic in cat_data["topic_list"]["topics"]:
|
||||||
|
write.writerow([topic["id"], topic["title"], topic["tags"], f'{self.url}t/{topic["id"]}'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
dis = Discourse("https://kb.hs3.pl/")
|
dis = Discourse("https://kb.hs3.pl/")
|
||||||
dis.get_category_topics(9)
|
dis.category_topics_csv(9)
|
||||||
20
zasoby.csv
20
zasoby.csv
|
|
@ -0,0 +1,20 @@
|
||||||
|
id,title,tags,url
|
||||||
|
45,Jak stworzyć nowy wpis do bazy zasobów Hackerspace Trójmiasto?,[],https://kb.hs3.pl/t/45
|
||||||
|
20,O kategorii: Baza Wiedzy Hackerspace'u,[],https://kb.hs3.pl/t/20
|
||||||
|
108,PC Engines APU2 Router Box,"['cow-work', 'networking']",https://kb.hs3.pl/t/108
|
||||||
|
61,HS3 BOFH,"['cow-work', 'garage', 'events', 'bofh']",https://kb.hs3.pl/t/61
|
||||||
|
93,King Bob,['cow-work'],https://kb.hs3.pl/t/93
|
||||||
|
92,Drukarka 3D Creality K1 Max,"['tools', 'workshop', '3d-print']",https://kb.hs3.pl/t/92
|
||||||
|
91,Drukarka 3D Creality Ender 3,"['tools', 'workshop', '3d-print']",https://kb.hs3.pl/t/91
|
||||||
|
90,Chciejlista,[],https://kb.hs3.pl/t/90
|
||||||
|
85,Komu powinien służyć Spejs,[],https://kb.hs3.pl/t/85
|
||||||
|
84,Budżet,[],https://kb.hs3.pl/t/84
|
||||||
|
83,Hackerspace Dragon Dreaming,[],https://kb.hs3.pl/t/83
|
||||||
|
82,Biblioteka,"['cow-work', 'books']",https://kb.hs3.pl/t/82
|
||||||
|
66,Apteczki,"['cow-work', 'garage', 'bhp']",https://kb.hs3.pl/t/66
|
||||||
|
44,Brayton Power,"['garage', 'projects']",https://kb.hs3.pl/t/44
|
||||||
|
52,Evil Submarine,"['cow-work', 'projects']",https://kb.hs3.pl/t/52
|
||||||
|
50,Infinity mirror (duże),"['garage', 'projects']",https://kb.hs3.pl/t/50
|
||||||
|
47,Cricut Maker 3 ploter tnący,"['tools', 'workshop']",https://kb.hs3.pl/t/47
|
||||||
|
41,Wiertarka PSB 500 RE BOSCH,"['garage', 'tools']",https://kb.hs3.pl/t/41
|
||||||
|
46,What the Duck,"['cow-work', 'wled']",https://kb.hs3.pl/t/46
|
||||||
|
Loading…
Add table
Add a link
Reference in a new issue