From 04c07e4774fa1a1637979197680d593c7f5bb07d Mon Sep 17 00:00:00 2001 From: niclas Date: Tue, 12 Mar 2024 14:06:14 +0100 Subject: [PATCH] Add [cluster] authors --- clusters/intelligence-agencies.json | 13 ++++++++++++- tools/IntelAgencies/main.py | 3 ++- tools/IntelAgencies/modules/api.py | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/clusters/intelligence-agencies.json b/clusters/intelligence-agencies.json index d34d3d1..fd7b254 100644 --- a/clusters/intelligence-agencies.json +++ b/clusters/intelligence-agencies.json @@ -1,5 +1,16 @@ { - "authors": "Wikipedia", + "authors": [ + "Graham87", + "Frietjes", + "Narky Blert", + "Pkbwcgs", + "Girth Summit", + "InternetArchiveBot", + "AnomieBOT", + "GreenMeansGo", + "MusikBot", + "Trappist the monk" + ], "category": "Intelligence Agencies", "description": "List of intelligence agencies", "name": "Intelligence Agencies", diff --git a/tools/IntelAgencies/main.py b/tools/IntelAgencies/main.py index 4e69bea..8f9c45a 100644 --- a/tools/IntelAgencies/main.py +++ b/tools/IntelAgencies/main.py @@ -155,6 +155,7 @@ if __name__ == '__main__': else: print(f'Error: {content}') + authors = [x['name'] for x in wiki.get_authors(page_title)] # Write to files galaxy = Galaxy( description="List of intelligence agencies", @@ -168,7 +169,7 @@ if __name__ == '__main__': galaxy.save_to_file(os.path.join(GALAXY_PATH, f'{GALAXY_NAME}.json')) cluster = Cluster( - authors="Wikipedia", + authors=authors, category="Intelligence Agencies", description="List of intelligence agencies", name="Intelligence Agencies", diff --git a/tools/IntelAgencies/modules/api.py b/tools/IntelAgencies/modules/api.py index b77b64c..05a772c 100644 --- a/tools/IntelAgencies/modules/api.py +++ b/tools/IntelAgencies/modules/api.py @@ -51,6 +51,22 @@ class WikipediaAPI(): response = requests.get(self.base_url, params=params) data = response.json() return data['parse']['text']['*'] + except Exception as e: + print(f'Error: {e}') + return None + + def get_authors(self, page_title): + params = { + 'action': 'query', + 'format': 'json', + 'titles': page_title, + 'prop': 'contributors', + } + try: + response = requests.get(self.base_url, params=params) + data = response.json() + page_id = next(iter(data['query']['pages'])) + return data['query']['pages'][page_id]['contributors'] except Exception as e: print(f'Error: {e}') return None \ No newline at end of file