diff --git a/flaskinventory/templates/view/elements/source/audience.html b/flaskinventory/templates/view/elements/source/audience.html
index 1c0377e8..2067812d 100644
--- a/flaskinventory/templates/view/elements/source/audience.html
+++ b/flaskinventory/templates/view/elements/source/audience.html
@@ -13,20 +13,8 @@
{% if entry.get('audience_size|data_from') or entry.get('audience_size|datafrom') %}
Data from |
{% endif %}
- {% if entry.get('audience_size|daily_visitors') %}
- Daily Visitors |
- {% endif %}
- {% if entry.get('audience_size|likes') %}
- Likes |
- {% endif %}
- {% if entry.get('audience_size|subscribers') %}
- Subscribers |
- {% endif %}
- {% if entry.get('audience_size|copies_sold') %}
- Copies Sold |
- {% endif %}
- {% if entry.get('audience_size|followers') %}
- Followers |
+ {% if entry.get('audience_size|unit') %}
+ {{entry.get('audience_size|unit')['0']|title }} |
{% endif %}
@@ -39,20 +27,8 @@
source
{% endif %}
- {% if entry.get('audience_size|daily_visitors') %}
- {{ "{0:,}".format(entry.get('audience_size|daily_visitors')[loop.index0|string] | int) }} |
- {% endif %}
- {% if entry.get('audience_size|likes') %}
- {{ "{0:,}".format(entry.get('audience_size|likes')[loop.index0|string] | int) }} |
- {% endif %}
- {% if entry.get('audience_size|subscribers') %}
- {{ "{0:,}".format(entry.get('audience_size|subscribers')[loop.index0|string] | int) }} |
- {% endif %}
- {% if entry.get('audience_size|copies_sold') %}
- {{ "{0:,}".format(entry.get('audience_size|copies_sold')[loop.index0|string] | int) }} |
- {% endif %}
- {% if entry.get('audience_size|followers') %}
- {{ "{0:,}".format(entry.get('audience_size|followers')[loop.index0|string] | int) }} |
+ {% if entry.get('audience_size|count') %}
+ {{ "{0:,}".format(entry.get('audience_size|count')[loop.index0|string] | int) }} |
{% endif %}
diff --git a/tools/change_audience_size_structure.py b/tools/change_audience_size_structure.py
new file mode 100644
index 00000000..5d1fee69
--- /dev/null
+++ b/tools/change_audience_size_structure.py
@@ -0,0 +1,170 @@
+import pydgraph
+import json
+import sys
+from colorama import init, deinit, Fore, Style
+
+def main():
+ init()
+ print(Fore.RED + 'WARNING!' + Style.RESET_ALL + " You are about to irreversibly change all entries.")
+ user_warning = input('Are you sure you want to proceed? (y/n): ')
+
+ if user_warning.lower() != 'y':
+ print('Aborted')
+ sys.exit()
+
+
+ client_stub = pydgraph.DgraphClientStub('localhost:9080')
+ client = pydgraph.DgraphClient(client_stub)
+
+ print(Fore.YELLOW + 'Running: Websites: Daily Visitors ' + Style.RESET_ALL)
+
+ query_string = """
+ query {
+ c(func: eq(unique_name, "website")) {
+ u as uid
+ }
+ q(func: type("Source"))
+ @filter(has(audience_size) AND uid_in(channel, uid(u))) @cascade {
+ uid
+ audience_size @facets(gt(daily_visitors, 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|daily_visitors']
+ e['audience_size|unit'] = {'0': 'daily visitors'}
+ 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|daily_visitors')
+
+ txn = client.txn()
+
+ try:
+ txn.mutate(set_obj=result['q'])
+ txn.commit()
+ finally:
+ txn.discard()
+
+ print(Fore.YELLOW + 'Running: Twitter / Instagram / Telegram / VK: Followers' + Style.RESET_ALL)
+
+ query_string = """
+ query {
+ c(func: type(Channel)) @filter(eq(unique_name, ["twitter", "telegram", "instagram", "vkontakte"])) {
+ u as uid
+ }
+ q(func: type("Source"))
+ @filter(has(audience_size) AND uid_in(channel, uid(u))) @cascade {
+ uid
+ audience_size @facets(gt(followers, 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|followers']
+ e['audience_size|unit'] = {'0': 'followers'}
+ 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|followers')
+
+ 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)
+
+ query_string = """
+ query {
+ c(func: type(Channel)) @filter(eq(unique_name, "print")) {
+ u as uid
+ }
+ q(func: type("Source"))
+ @filter(has(audience_size) AND uid_in(channel, uid(u))) @cascade {
+ uid
+ audience_size @facets(gt(subscribers, 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|subscribers']
+ e['audience_size|unit'] = {'0': 'subscribers'}
+ 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|subscribers')
+
+ txn = client.txn()
+
+ try:
+ txn.mutate(set_obj=result['q'])
+ txn.commit()
+ finally:
+ txn.discard()
+
+
+
+ query_string = """
+ query {
+ c(func: type(Channel)) @filter(eq(unique_name, "print")) {
+ u as uid
+ }
+ q(func: type("Source"))
+ @filter(has(audience_size) AND uid_in(channel, uid(u))) @cascade {
+ uid
+ audience_size @facets(gt(copies_sold, 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|copies_sold']
+ e['audience_size|unit'] = {'0': 'copies sold'}
+ 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|copies_sold')
+
+ txn = client.txn()
+
+ try:
+ txn.mutate(set_obj=result['q'])
+ txn.commit()
+ finally:
+ txn.discard()
+
+ print(Fore.GREEN + 'DONE!' + Style.RESET_ALL)
+ deinit()
+
+if __name__ == '__main__':
+ main()
\ No newline at end of file