| 
									
										
										
										
											2020-04-03 08:54:53 +00:00
										 |  |  | __filename__ = "donate.py" | 
					
						
							|  |  |  | __author__ = "Bob Mottram" | 
					
						
							|  |  |  | __license__ = "AGPL3+" | 
					
						
							| 
									
										
										
										
											2023-01-21 23:03:30 +00:00
										 |  |  | __version__ = "1.4.0" | 
					
						
							| 
									
										
										
										
											2020-04-03 08:54:53 +00:00
										 |  |  | __maintainer__ = "Bob Mottram" | 
					
						
							| 
									
										
										
										
											2021-09-10 16:14:50 +00:00
										 |  |  | __email__ = "bob@libreserver.org" | 
					
						
							| 
									
										
										
										
											2020-04-03 08:54:53 +00:00
										 |  |  | __status__ = "Production" | 
					
						
							| 
									
										
										
										
											2021-06-15 15:08:12 +00:00
										 |  |  | __module_group__ = "Profile Metadata" | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-11 17:17:23 +00:00
										 |  |  | from utils import get_attachment_property_value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-29 21:55:09 +00:00
										 |  |  | def _get_donation_types() -> []: | 
					
						
							| 
									
										
										
										
											2020-04-03 08:54:53 +00:00
										 |  |  |     return ('patreon', 'paypal', 'gofundme', 'liberapay', | 
					
						
							|  |  |  |             'kickstarter', 'indiegogo', 'crowdsupply', | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             'subscribestar') | 
					
						
							| 
									
										
										
										
											2020-03-22 21:16:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 08:54:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  | def _get_website_strings() -> []: | 
					
						
							| 
									
										
										
										
											2021-08-12 20:56:00 +00:00
										 |  |  |     return ['www', 'website', 'web', 'homepage'] | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-04 21:07:55 +00:00
										 |  |  | def _get_gemini_strings() -> []: | 
					
						
							| 
									
										
										
										
											2022-11-04 21:13:07 +00:00
										 |  |  |     return ['gemini', 'capsule', 'gemlog'] | 
					
						
							| 
									
										
										
										
											2022-11-04 21:07:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-28 18:13:52 +00:00
										 |  |  | def get_donation_url(actor_json: {}) -> str: | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |     """Returns a link used for donations
 | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2021-12-26 10:29:52 +00:00
										 |  |  |     if not actor_json.get('attachment'): | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |         return '' | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     donation_type = _get_donation_types() | 
					
						
							| 
									
										
										
										
											2021-12-26 10:32:45 +00:00
										 |  |  |     for property_value in actor_json['attachment']: | 
					
						
							| 
									
										
										
										
											2022-05-11 16:10:38 +00:00
										 |  |  |         name_value = None | 
					
						
							|  |  |  |         if property_value.get('name'): | 
					
						
							|  |  |  |             name_value = property_value['name'] | 
					
						
							|  |  |  |         elif property_value.get('schema:name'): | 
					
						
							|  |  |  |             name_value = property_value['schema:name'] | 
					
						
							|  |  |  |         if not name_value: | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 16:10:38 +00:00
										 |  |  |         if name_value.lower() not in donation_type: | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2021-12-26 10:32:45 +00:00
										 |  |  |         if not property_value.get('type'): | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 17:17:23 +00:00
										 |  |  |         prop_value_name, prop_value = \ | 
					
						
							|  |  |  |             get_attachment_property_value(property_value) | 
					
						
							|  |  |  |         if not prop_value: | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 16:16:34 +00:00
										 |  |  |         if not property_value['type'].endswith('PropertyValue'): | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 17:17:23 +00:00
										 |  |  |         if '<a href="' not in property_value[prop_value_name]: | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 17:17:23 +00:00
										 |  |  |         donate_url = property_value[prop_value_name].split('<a href="')[1] | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |         if '"' in donate_url: | 
					
						
							|  |  |  |             return donate_url.split('"')[0] | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |     return '' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 08:54:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-28 18:13:52 +00:00
										 |  |  | def get_website(actor_json: {}, translate: {}) -> str: | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |     """Returns a web address link
 | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2021-12-26 10:29:52 +00:00
										 |  |  |     if not actor_json.get('attachment'): | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |         return '' | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     match_strings = _get_website_strings() | 
					
						
							|  |  |  |     match_strings.append(translate['Website'].lower()) | 
					
						
							| 
									
										
										
										
											2021-12-26 10:32:45 +00:00
										 |  |  |     for property_value in actor_json['attachment']: | 
					
						
							| 
									
										
										
										
											2022-05-11 16:10:38 +00:00
										 |  |  |         name_value = None | 
					
						
							|  |  |  |         if property_value.get('name'): | 
					
						
							|  |  |  |             name_value = property_value['name'] | 
					
						
							|  |  |  |         elif property_value.get('schema:name'): | 
					
						
							|  |  |  |             name_value = property_value['schema:name'] | 
					
						
							|  |  |  |         if not name_value: | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 16:10:38 +00:00
										 |  |  |         if name_value.lower() not in match_strings: | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2021-12-26 10:32:45 +00:00
										 |  |  |         if not property_value.get('type'): | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 17:17:23 +00:00
										 |  |  |         prop_value_name, _ = \ | 
					
						
							|  |  |  |             get_attachment_property_value(property_value) | 
					
						
							|  |  |  |         if not prop_value_name: | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 16:16:34 +00:00
										 |  |  |         if not property_value['type'].endswith('PropertyValue'): | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 17:17:23 +00:00
										 |  |  |         return property_value[prop_value_name] | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |     return '' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-04 21:07:55 +00:00
										 |  |  | def get_gemini_link(actor_json: {}, translate: {}) -> str: | 
					
						
							|  |  |  |     """Returns a gemini link
 | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     if not actor_json.get('attachment'): | 
					
						
							|  |  |  |         return '' | 
					
						
							|  |  |  |     match_strings = _get_gemini_strings() | 
					
						
							|  |  |  |     for property_value in actor_json['attachment']: | 
					
						
							|  |  |  |         name_value = None | 
					
						
							|  |  |  |         if property_value.get('name'): | 
					
						
							|  |  |  |             name_value = property_value['name'] | 
					
						
							|  |  |  |         elif property_value.get('schema:name'): | 
					
						
							|  |  |  |             name_value = property_value['schema:name'] | 
					
						
							|  |  |  |         if not name_value: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         if name_value.lower() not in match_strings: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         if not property_value.get('type'): | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         prop_value_name, _ = \ | 
					
						
							|  |  |  |             get_attachment_property_value(property_value) | 
					
						
							|  |  |  |         if not prop_value_name: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         if not property_value['type'].endswith('PropertyValue'): | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         return property_value[prop_value_name] | 
					
						
							|  |  |  |     return '' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  | def set_donation_url(actor_json: {}, donate_url: str) -> None: | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |     """Sets a link used for donations
 | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     not_url = False | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |     if '.' not in donate_url: | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         not_url = True | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |     if '://' not in donate_url: | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         not_url = True | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |     if ' ' in donate_url: | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         not_url = True | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |     if '<' in donate_url: | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         not_url = True | 
					
						
							| 
									
										
										
										
											2020-07-06 10:31:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-26 10:29:52 +00:00
										 |  |  |     if not actor_json.get('attachment'): | 
					
						
							|  |  |  |         actor_json['attachment'] = [] | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     donation_type = _get_donation_types() | 
					
						
							|  |  |  |     donate_name = None | 
					
						
							|  |  |  |     for payment_service in donation_type: | 
					
						
							|  |  |  |         if payment_service in donate_url: | 
					
						
							|  |  |  |             donate_name = payment_service | 
					
						
							|  |  |  |     if not donate_name: | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |         return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-17 23:35:59 +00:00
										 |  |  |     # remove any existing value | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     property_found = None | 
					
						
							| 
									
										
										
										
											2021-12-26 10:32:45 +00:00
										 |  |  |     for property_value in actor_json['attachment']: | 
					
						
							| 
									
										
										
										
											2022-05-11 16:10:38 +00:00
										 |  |  |         name_value = None | 
					
						
							|  |  |  |         if property_value.get('name'): | 
					
						
							|  |  |  |             name_value = property_value['name'] | 
					
						
							|  |  |  |         elif property_value.get('schema:name'): | 
					
						
							|  |  |  |             name_value = property_value['schema:name'] | 
					
						
							|  |  |  |         if not name_value: | 
					
						
							| 
									
										
										
										
											2019-12-17 23:35:59 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2021-12-26 10:32:45 +00:00
										 |  |  |         if not property_value.get('type'): | 
					
						
							| 
									
										
										
										
											2019-12-17 23:35:59 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 16:10:38 +00:00
										 |  |  |         if not name_value.lower() != donate_name: | 
					
						
							| 
									
										
										
										
											2019-12-17 23:35:59 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         property_found = property_value | 
					
						
							| 
									
										
										
										
											2019-12-17 23:35:59 +00:00
										 |  |  |         break | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     if property_found: | 
					
						
							|  |  |  |         actor_json['attachment'].remove(property_found) | 
					
						
							|  |  |  |     if not_url: | 
					
						
							| 
									
										
										
										
											2020-07-06 10:31:00 +00:00
										 |  |  |         return | 
					
						
							| 
									
										
										
										
											2019-12-17 23:35:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     donate_value = \ | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |         '<a href="' + donate_url + \ | 
					
						
							| 
									
										
										
										
											2020-04-03 08:54:53 +00:00
										 |  |  |         '" rel="me nofollow noopener noreferrer" target="_blank">' + \ | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |         donate_url + '</a>' | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-26 10:32:45 +00:00
										 |  |  |     for property_value in actor_json['attachment']: | 
					
						
							| 
									
										
										
										
											2022-05-11 16:10:38 +00:00
										 |  |  |         name_value = None | 
					
						
							|  |  |  |         if property_value.get('name'): | 
					
						
							|  |  |  |             name_value = property_value['name'] | 
					
						
							|  |  |  |         elif property_value.get('schema:name'): | 
					
						
							|  |  |  |             name_value = property_value['schema:name'] | 
					
						
							|  |  |  |         if not name_value: | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2021-12-26 10:32:45 +00:00
										 |  |  |         if not property_value.get('type'): | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 16:10:38 +00:00
										 |  |  |         if name_value.lower() != donate_name: | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 16:16:34 +00:00
										 |  |  |         if not property_value['type'].endswith('PropertyValue'): | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-05-11 17:17:23 +00:00
										 |  |  |         prop_value_name, _ = \ | 
					
						
							|  |  |  |             get_attachment_property_value(property_value) | 
					
						
							|  |  |  |         if not prop_value_name: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         property_value[prop_value_name] = donate_value | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |         return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     new_donate = { | 
					
						
							|  |  |  |         "name": donate_name, | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |         "type": "PropertyValue", | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         "value": donate_value | 
					
						
							| 
									
										
										
										
											2019-11-07 12:14:17 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     actor_json['attachment'].append(new_donate) | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  | def set_website(actor_json: {}, website_url: str, translate: {}) -> None: | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |     """Sets a web address
 | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |     website_url = website_url.strip() | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     not_url = False | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |     if '.' not in website_url: | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         not_url = True | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |     if '://' not in website_url: | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         not_url = True | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |     if ' ' in website_url: | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         not_url = True | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |     if '<' in website_url: | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         not_url = True | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-26 10:29:52 +00:00
										 |  |  |     if not actor_json.get('attachment'): | 
					
						
							|  |  |  |         actor_json['attachment'] = [] | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     match_strings = _get_website_strings() | 
					
						
							|  |  |  |     match_strings.append(translate['Website'].lower()) | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # remove any existing value | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     property_found = None | 
					
						
							| 
									
										
										
										
											2021-12-26 10:32:45 +00:00
										 |  |  |     for property_value in actor_json['attachment']: | 
					
						
							|  |  |  |         if not property_value.get('name'): | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2021-12-26 10:32:45 +00:00
										 |  |  |         if not property_value.get('type'): | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         if property_value['name'].lower() not in match_strings: | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |             continue | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |         property_found = property_value | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |         break | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     if property_found: | 
					
						
							|  |  |  |         actor_json['attachment'].remove(property_found) | 
					
						
							|  |  |  |     if not_url: | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |         return | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     new_entry = { | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |         "name": 'Website', | 
					
						
							|  |  |  |         "type": "PropertyValue", | 
					
						
							| 
									
										
										
										
											2021-12-31 18:11:17 +00:00
										 |  |  |         "value": website_url | 
					
						
							| 
									
										
										
										
											2021-08-12 20:40:23 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-01-02 12:38:22 +00:00
										 |  |  |     actor_json['attachment'].append(new_entry) | 
					
						
							| 
									
										
										
										
											2022-11-04 21:07:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def set_gemini_link(actor_json: {}, gemini_link: str, translate: {}) -> None: | 
					
						
							|  |  |  |     """Sets a gemini link
 | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     gemini_link = gemini_link.strip() | 
					
						
							|  |  |  |     not_link = False | 
					
						
							|  |  |  |     if '.' not in gemini_link: | 
					
						
							|  |  |  |         not_link = True | 
					
						
							|  |  |  |     if '://' not in gemini_link: | 
					
						
							|  |  |  |         not_link = True | 
					
						
							|  |  |  |     if ' ' in gemini_link: | 
					
						
							|  |  |  |         not_link = True | 
					
						
							|  |  |  |     if '<' in gemini_link: | 
					
						
							|  |  |  |         not_link = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if not actor_json.get('attachment'): | 
					
						
							|  |  |  |         actor_json['attachment'] = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     match_strings = _get_gemini_strings() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # remove any existing value | 
					
						
							|  |  |  |     property_found = None | 
					
						
							|  |  |  |     for property_value in actor_json['attachment']: | 
					
						
							|  |  |  |         if not property_value.get('name'): | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         if not property_value.get('type'): | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         if property_value['name'].lower() not in match_strings: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         property_found = property_value | 
					
						
							|  |  |  |         break | 
					
						
							|  |  |  |     if property_found: | 
					
						
							|  |  |  |         actor_json['attachment'].remove(property_found) | 
					
						
							|  |  |  |     if not_link: | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     new_entry = { | 
					
						
							|  |  |  |         "name": 'Gemini', | 
					
						
							|  |  |  |         "type": "PropertyValue", | 
					
						
							|  |  |  |         "value": gemini_link | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     actor_json['attachment'].append(new_entry) |