-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimages-network.py
37 lines (25 loc) · 1.05 KB
/
images-network.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
import os
import pandas
from utils.google_services import get_service
import utils.change
values = get_service().spreadsheets().values().get(
spreadsheetId=os.environ.get('PETITION_SPREADSHEET_ID'), range='unmask_netwok!A2:F').execute().get('values', [])
edges = []
nodes = []
for (url, slug, signatures, estetica, *subjects) in values:
nodes.append({
'id': slug,
'label': '',
'category': 'petition',
'image': f"{slug}.jpg"
})
for sub in subjects:
if sub and sub != '':
edges.append({'source': slug, 'target': sub})
edges = pandas.DataFrame(edges)
petition_nodes = pandas.DataFrame(nodes)
tag_nodes = pandas.DataFrame()
tag_nodes = tag_nodes.assign(id=edges['target'].unique(), label=lambda x: x['id'], category='subject')
edges.to_csv(utils.change.get_onedrive_path('csv', 'images-network', 'promask-edges.csv'), index=False)
pandas.concat([petition_nodes, tag_nodes], ignore_index=True).to_csv(
utils.change.get_onedrive_path('csv', 'images-network', 'promask-nodes.csv'), index=False)