Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
#177 #178 forgot about facebook...
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwunderbar666 committed Sep 1, 2022
1 parent d51ac09 commit 1d17512
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
8 changes: 1 addition & 7 deletions flaskinventory/edit/dgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ def get_audience(uid):
rows = []
# convert to list of dicts
if 'audience_size' not in data.keys():
cols = ['date']
if data['channel']['unique_name'] == 'print':
cols += ['copies_sold', 'data_from']
elif data['channel']['unique_name'] == 'facebook':
cols.append('likes')
else:
return False
cols = ['date', 'unit', 'count']
else:
keys = [key for key in data.keys() if key.startswith('audience_size|')]
for i, item in enumerate(data['audience_size']):
Expand Down
36 changes: 36 additions & 0 deletions tools/change_audience_size_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,42 @@ def main():
finally:
txn.discard()

print(Fore.YELLOW + 'Running: Facebook: Likes ' + Style.RESET_ALL)

query_string = """
query {
c(func: eq(unique_name, "facebook")) {
u as uid
}
q(func: type("Source"))
@filter(has(audience_size) AND uid_in(channel, uid(u))) @cascade {
uid
audience_size @facets(gt(likes, 0)) @facets
}
}
"""

res = client.txn().query(query_string)

result = json.loads(res.json)

for e in result['q']:
e['audience_size|count'] = e['audience_size|likes']
e['audience_size|unit'] = {'0': 'likes'}
if 'audience_size|datafrom' in e.keys():
e['audience_size|data_from'] = e.pop('audience_size|datafrom')

for e in result['q']:
e.pop('audience_size|likes')

txn = client.txn()

try:
txn.mutate(set_obj=result['q'])
txn.commit()
finally:
txn.discard()



print(Fore.YELLOW + 'Running: Print: subscribers, copies sold' + Style.RESET_ALL)
Expand Down

0 comments on commit 1d17512

Please sign in to comment.