diff --git a/scripts/weblate/double_languages.py b/scripts/weblate/double_languages.py index 56f8d11d..ffe7631f 100644 --- a/scripts/weblate/double_languages.py +++ b/scripts/weblate/double_languages.py @@ -1,16 +1,14 @@ - - import wlc import apikey import requests import math -import json from requests.exceptions import HTTPError +import json w=wlc.Weblate(apikey.myAPIKey) projects={'mobile':{},'server':{},'webapp':{},'glossary':{}} -projects['mobile']['shipped']='mattermost-mobile_master' +projects['mobile']['shipped']='mattermost-mobile-v2' projects['mobile']['wip']='mattermost-mobile-wip' projects['server']['shipped']='mattermost-server_master' projects['server']['wip']='mattermost-server-wip' @@ -18,31 +16,29 @@ projects['webapp']['wip']='mattermost-webapp-wip' projects['glossary']['shipped']='glossary' projects['glossary']['wip']='glossary' + current_notification_state={"state":"false"} previous_notification_state= json.load(open("./notification_state.txt")) for project in projects: shippedLanguages={} WIPLanguages={} -### GETTING THE SHIPPED LANGUAGES ### - #print('GETTING SHIPPED LANGUAGES FOR '+project) - shippedProjects=w.get('https://translate.mattermost.com/api/components/mattermost/'+projects[project]['shipped']+'/translations/') - for shippedLanguage in shippedProjects['results']: - if shippedLanguage['language']['code']=='en': - continue - shippedLanguageCode=shippedLanguage['language']['code'] - shippedLanguageName=shippedLanguage['language']['name'] - shippedLanguages[shippedLanguageCode]=shippedLanguageName + page='https://translate.mattermost.com/api/components/mattermost/'+projects[project]['shipped']+'/translations/' + while page : + shippedProjects=w.get(page) + page=shippedProjects['next'] + for shippedLanguage in shippedProjects['results']: + if shippedLanguage['language']['code']=='en': + continue + shippedLanguageCode=shippedLanguage['language']['code'] + shippedLanguageName=shippedLanguage['language']['name'] + shippedLanguages[shippedLanguageCode]=shippedLanguageName - #print('GETTING WIP LANGUAGES FOR '+project) - page=1 - next='https://translate.mattermost.com/api/components/i18n-wip/'+projects[project]['wip']+'/translations/' - WIPProjects=w.get(next) - lastpage=math.ceil(WIPProjects['count']/20) - while page<=lastpage: - next='https://translate.mattermost.com/api/components/i18n-wip/'+projects[project]['wip']+'/translations/?page='+str(page) - WIPProjects=w.get(next) - page=page+1 + + page='https://translate.mattermost.com/api/components/i18n-wip/'+projects[project]['wip']+'/translations/' + while page : + WIPProjects=w.get(page) + page=WIPProjects['next'] for WIPLanguage in WIPProjects['results']: if WIPLanguage['language']['code']=='en': continue @@ -50,23 +46,24 @@ WIPLanguageName=WIPLanguage['language']['name'] WIPLanguages[WIPLanguageCode]=WIPLanguageName -### GETTING REMOVING THE WIP LANGUAGES THAT ARE ALREADY IN SHIPPED ### for languageToRemove in shippedLanguages.keys() & WIPLanguages.keys(): current_notification_state['state']="true" + if (previous_notification_state['state']=="false"): try: headers = {'Content-Type': 'application/json',} - values = '{ "text": "Hi @ctlaltdieliet and @carrie.warner: a shipped language is detected in WIP ('+languageToRemove+') in this '+project+' This project is locked now"}' + values = '{ "text": "Hi @ctlaltdieliet and @carrie.warner: a shipped language is detected in WIP ('+languageToRemove+') in this '+project+' This project is locked now!"}' responseMattermost = requests.post(apikey.i18nWebhook,headers=headers,data=values) responseMattermost.raise_for_status() + current_notification_state['state']="true" except HTTPError as http_err: - print('HTTP error occurred while notifying Mattermost channel: '+http_err) + print('HTTP error occurred while notifying Mattermost channel: '+http_err) except Exception as err: print('Other error occurred while notifying Mattermost channel: '+err.message+' '+err.args) try: responseWeblate=w.request('post','https://translate.mattermost.com/api/components/i18n-wip/'+projects[project]['wip']+'/lock/',{'lock':True}) except HTTPError as http_err: - print('HTTP error occurred while locking '+projects[project]['wip']+': '+http_err) + print('HTTP error occurred while locking '+projects[project]['wip']+': '+http_err) except Exception as err: print('Other error occurred while locking : '+ projects[project]['wip']+' '+err.message+' '+err.args) json.dump(current_notification_state,open("./notification_state.txt",'w')) diff --git a/scripts/weblate/locks.txt b/scripts/weblate/locks.txt index 020b9bb6..a0c52aa9 100644 --- a/scripts/weblate/locks.txt +++ b/scripts/weblate/locks.txt @@ -1 +1 @@ -{"mattermost/mattermost-mobile-v2-channel_notified": "2022-12-25, 10:35:32", "mattermost/mattermost-server_master-channel_notified": "2022-12-25, 10:35:33", "mattermost/mattermost-webapp_master-channel_notified": "2022-12-25, 10:35:33", "mattermost/mattermost-desktop-channel_notified": "2022-12-25, 10:35:33", "mattermost/glossary-channel_notified": "2022-12-25, 10:35:33", "focalboard/webapp-channel_notified": "2022-12-25, 10:35:33", "playbooks/webapp-channel_notified": "2022-12-25, 10:35:33"} \ No newline at end of file +{"mattermost/mattermost-mobile-v2": {"locked": false}, "mattermost/mattermost-mobile-v2-channel_notified": "2023-02-21, 09:48:01", "mattermost/mattermost-server-monorepo": {"locked": false}, "mattermost/mattermost-server-monorepo-channel_notified": "2023-03-27, 12:51:54", "mattermost/webapp-monorepo": {"locked": false}, "mattermost/webapp-monorepo-channel_notified": "2023-03-27, 12:51:55", "mattermost/mattermost-desktop": {"locked": false}, "mattermost/mattermost-desktop-channel_notified": "2023-03-06, 15:34:02", "mattermost/glossary": {"locked": false}, "mattermost/glossary-channel_notified": "2023-02-16, 07:14:02", "focalboard/webapp": {"locked": false}, "focalboard/webapp-channel_notified": "2023-01-20, 00:38:02", "playbooks/webapp": {"locked": false}, "playbooks/webapp-channel_notified": "2023-02-15, 14:12:02"} \ No newline at end of file diff --git a/scripts/weblate/weblate_locks_notify_community.py b/scripts/weblate/weblate_locks_notify_community.py index bef2fa4c..5addb36e 100644 --- a/scripts/weblate/weblate_locks_notify_community.py +++ b/scripts/weblate/weblate_locks_notify_community.py @@ -10,9 +10,9 @@ import datetime as DT projects={'mobile':{},'server':{},'webapp':{},'desktop':{},'glossary':{}} -projects['mobile']='mattermost/mattermost-mobile-v2' -projects['server']='mattermost/mattermost-server_master' -projects['webapp']='mattermost/mattermost-webapp_master' +projects['mobile']='mattermost/mattermost-mobile_master' +projects['server']='mattermost/mattermost-server-monorepo' +projects['webapp']='mattermost/webapp_monorepo' projects['desktop']='mattermost/mattermost-desktop' projects['focalboard']='focalboard/webapp' projects['playbooks']='playbooks/webapp' @@ -39,30 +39,24 @@ def notificateChannel(project,current_lock): headers = {'Content-Type': 'application/json',} current_locks[projects[project]]=current_lock current_locks[projects[project]+"-channel_notified"]=now - print("locked sent") response = requests.post(apikey.communityWebhook,headers=headers,data=values) response.raise_for_status() except HTTPError as http_err: print(f'HTTP error occurred while notifying Mattermost-channel: {http_err}') except Exception as err: print(f'Other error occurred while notifying Mattermost-channel: {err.message} {err.args}') - else: - print('Success!') for project in projects: now=datetime.now().strftime("%Y-%m-%d, %H:%M:%S") - print(now) current_lock=w.get('https://translate.mattermost.com/api/components/'+projects[project]+'/lock/') current_locks[projects[project]]=current_lock if (previous_locks[projects[project]]!=current_lock): - print("SENT NOTIFICICATION CAUSE LOCK HAS CHANGED") notificateChannel(project,current_lock) current_locks[projects[project]+"-channel_notified"]=now else: previous_notification = datetime.strptime(previous_locks[projects[project]+"-channel_notified"], '%Y-%m-%d, %H:%M:%S') current_locks[projects[project]+"-channel_notified"]=previous_locks[projects[project]+"-channel_notified"] if (datetime.now()-DT.timedelta(days=7))>previous_notification and current_lock['locked']: - print("reminder for "+str(projects[project])) notificateChannel(project,current_lock) current_locks[projects[project]+"-channel_notified"]=now json.dump(current_locks,open("locks.txt",'w'))