From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- share/extensions/other/clipart/sources/reactome.py | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 share/extensions/other/clipart/sources/reactome.py (limited to 'share/extensions/other/clipart/sources/reactome.py') diff --git a/share/extensions/other/clipart/sources/reactome.py b/share/extensions/other/clipart/sources/reactome.py new file mode 100644 index 0000000..1a1c8b3 --- /dev/null +++ b/share/extensions/other/clipart/sources/reactome.py @@ -0,0 +1,64 @@ +# +# Copyright 2021 Martin Owens +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +""" +Access Reactome Content Services. +""" + +import re + +from import_sources import RemoteSource + +TAG_REX = re.compile(r'<[^<]+?>') + +class Reactome(RemoteSource): + name = 'Reactome (Bio)' + icon = 'sources/reactome.svg' + search_url = "https://reactome.org/ContentService/search/query" + file_url = "https://reactome.org/icon/{stId}.svg" + icon_url = "https://reactome.org/icon/{stId}.png" + all_licence = "cc-by-sa-4.0" + + def search(self, query): + params = { + "query": query, + "types": "Icon", + "cluster": "true", + "Start row": 0, + "rows": 100, + } + response = {} + try: + response = self.session.get(self.search_url, params=params).json() + except Exception: + pass + + if 'messages' in response and 'No entries' in response['messages'][0]: + return + for cats in response.get('results', []): + for entry in cats['entries']: + yield { + 'id': entry['dbId'], + 'name': TAG_REX.sub('', entry['name']), + 'author': 'Reactome/'+entry.get('iconDesignerName', "Unknown"), + 'summary': TAG_REX.sub('', entry.get('summation', '')), + 'created': None, # No data + 'popularity': 0, # No data + 'thumbnail': self.icon_url.format(**entry), + 'file': self.file_url.format(**entry), + 'license': self.all_licence, + } + -- cgit v1.2.3