diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..16c851e --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,28 @@ +# This workflow will generate a distribution and upload it to PyPI + +name: Publish to pypi +on: + workflow_dispatch: + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: dev + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + - name: Install Build Tools + run: | + python -m pip install build wheel + - name: Build Distribution Packages + run: | + python setup.py bdist_wheel + - name: Publish to Test PyPI + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{secrets.PYPI_TOKEN}} diff --git a/.github/workflows/sync_tx.yml b/.github/workflows/sync_tx.yml new file mode 100644 index 0000000..5e7d307 --- /dev/null +++ b/.github/workflows/sync_tx.yml @@ -0,0 +1,37 @@ +name: Run script on merge to dev by gitlocalize-app + +on: + workflow_dispatch: + push: + branches: + - dev + +jobs: + run-script: + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + with: + ref: dev + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.9 + + - name: Run script if manual dispatch + if: github.event_name == 'workflow_dispatch' + run: | + python scripts/sync_translations.py + + - name: Run script if merged by gitlocalize-app[bot] + if: github.event_name == 'push' && github.event.head_commit.author.username == 'gitlocalize-app[bot]' + run: | + python scripts/sync_translations.py + + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Update translations + branch: dev diff --git a/LICENSE b/LICENSE index b014aec..617e3cd 100644 --- a/LICENSE +++ b/LICENSE @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2024 Casimiro Ferreira Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -201,11 +201,3 @@ See the License for the specific language governing permissions and limitations under the License. -======================================================================= - -Component licenses for mycroft-core: - -The mycroft-core software references various Python Packages (via PIP), -each of which has a separate license. All are compatible with the -Apache 2.0 license. See the referenced packages listed in the -"requirements/requirements.txt" file for specific terms and conditions. diff --git a/__init__.py b/__init__.py index 248aa8d..56877d1 100644 --- a/__init__.py +++ b/__init__.py @@ -1,9 +1,10 @@ import tempfile -from datetime import timedelta, datetime +from datetime import datetime from os.path import join, dirname from time import sleep import matplotlib.pyplot as plt +import requests from lingua_franca.format import nice_duration from matplotlib.offsetbox import OffsetImage, AnnotationBbox from mpl_toolkits.basemap import Basemap @@ -11,7 +12,6 @@ from ovos_workshop.decorators import resting_screen_handler from ovos_workshop.intents import IntentBuilder from ovos_workshop.skills import OVOSSkill -from requests_cache import CachedSession class ISSLocationSkill(OVOSSkill): @@ -32,15 +32,12 @@ def __init__(self, *args, **kwargs): self.settings["iss_icon"] = "iss3.png" if "dpi" not in self.settings: self.settings["dpi"] = 500 - _expire_after = timedelta(minutes=5) - self._session = CachedSession(backend='memory', - expire_after=_expire_after) def update_picture(self): try: - data = self._session.get( + data = requests.get( "http://api.open-notify.org/iss-now.json").json() - astronauts = self._session.get( + astronauts = requests.get( "http://api.open-notify.org/astros.json").json() self.settings["astronauts"] = astronauts["people"] @@ -59,7 +56,7 @@ def update_picture(self): land_names = "http://api.geonames.org/countryCodeJSON" # reverse geo - data = self._session.get(ocean_names, params=params).json() + data = requests.get(ocean_names, params=params).json() try: toponym = "The " + data['ocean']['name'] except: @@ -72,13 +69,12 @@ def update_picture(self): "formatted": True, "style": "full" } - data = self._session.get(land_names, - params=params).json() + data = requests.get(land_names, + params=params).json() toponym = data['countryName'] except: toponym = "unknown" - if not self.lang.lower().startswith("en") and \ - toponym != "unknown": + if not self.lang.lower().startswith("en") and toponym != "unknown": toponym = self.translator.translate(toponym, self.lang) self.settings['toponym'] = toponym image = self.generate_map(lat, lon) @@ -182,7 +178,7 @@ def handle_when(self, message): lon = self.location["coordinate"]["longitude"] if not self.settings.get("passing_by"): params = {"lat": lat, "lon": lon} - passing = self._session.get( + passing = requests.get( "http://api.open-notify.org/iss-pass.json", params=params).json() self.settings["passing_by"] = passing["response"] @@ -244,3 +240,10 @@ def handle_number(self, message): self.speak_dialog("number", {"number": num}, wait=True) sleep(1) self.gui.clear() + + +if __name__ == "__main__": + from ovos_utils.fakebus import FakeBus + + s = ISSLocationSkill(skill_id="fake.test", bus=FakeBus()) + s.update_picture() diff --git a/dialog/en-us/about.dialog b/locale/en-us/about.dialog similarity index 100% rename from dialog/en-us/about.dialog rename to locale/en-us/about.dialog diff --git a/vocab/en-us/about.intent b/locale/en-us/about.intent similarity index 100% rename from vocab/en-us/about.intent rename to locale/en-us/about.intent diff --git a/vocab/en-us/how_many.voc b/locale/en-us/how_many.voc similarity index 100% rename from vocab/en-us/how_many.voc rename to locale/en-us/how_many.voc diff --git a/vocab/en-us/iss.voc b/locale/en-us/iss.voc similarity index 100% rename from vocab/en-us/iss.voc rename to locale/en-us/iss.voc diff --git a/dialog/en-us/location.current.dialog b/locale/en-us/location.current.dialog similarity index 100% rename from dialog/en-us/location.current.dialog rename to locale/en-us/location.current.dialog diff --git a/dialog/en-us/location.unknown.dialog b/locale/en-us/location.unknown.dialog similarity index 100% rename from dialog/en-us/location.unknown.dialog rename to locale/en-us/location.unknown.dialog diff --git a/dialog/en-us/location.when.dialog b/locale/en-us/location.when.dialog similarity index 100% rename from dialog/en-us/location.when.dialog rename to locale/en-us/location.when.dialog diff --git a/dialog/en-us/number.dialog b/locale/en-us/number.dialog similarity index 100% rename from dialog/en-us/number.dialog rename to locale/en-us/number.dialog diff --git a/vocab/en-us/onboard.voc b/locale/en-us/onboard.voc similarity index 100% rename from vocab/en-us/onboard.voc rename to locale/en-us/onboard.voc diff --git a/vocab/en-us/when_iss.intent b/locale/en-us/when_iss.intent similarity index 100% rename from vocab/en-us/when_iss.intent rename to locale/en-us/when_iss.intent diff --git a/vocab/en-us/where_iss.intent b/locale/en-us/where_iss.intent similarity index 100% rename from vocab/en-us/where_iss.intent rename to locale/en-us/where_iss.intent diff --git a/dialog/en-us/who.dialog b/locale/en-us/who.dialog similarity index 100% rename from dialog/en-us/who.dialog rename to locale/en-us/who.dialog diff --git a/vocab/en-us/who.voc b/locale/en-us/who.voc similarity index 100% rename from vocab/en-us/who.voc rename to locale/en-us/who.voc diff --git a/requirements.txt b/requirements.txt index 0c126a1..118f063 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ matplotlib -https://github.com/matplotlib/basemap/archive/master.zip +basemap pillow requests -requests-cache -mtranslate \ No newline at end of file +requests-cache \ No newline at end of file diff --git a/scripts/prepare_translations.py b/scripts/prepare_translations.py new file mode 100644 index 0000000..7071ed9 --- /dev/null +++ b/scripts/prepare_translations.py @@ -0,0 +1,53 @@ +"""this script should run every time the contents of the locale folder change +except if PR originated from @gitlocalize-app +TODO - on commit to dev +""" + +import json +from os.path import dirname +import os + +locale = f"{dirname(dirname(__file__))}/locale" +tx = f"{dirname(dirname(__file__))}/translations" + + +for lang in os.listdir(locale): + intents = {} + dialogs = {} + vocs = {} + regexes = {} + for root, _, files in os.walk(f"{locale}/{lang}"): + b = root.split(f"/{lang}")[-1] + + for f in files: + if b: + fid = f"{b}/{f}" + else: + fid = f + with open(f"{root}/{f}") as fi: + strings = [l.replace("{{", "{").replace("}}", "}") + for l in fi.read().split("\n") if l.strip() + and not l.startswith("#")] + + if fid.endswith(".intent"): + intents[fid] = strings + elif fid.endswith(".locale"): + dialogs[fid] = strings + elif fid.endswith(".voc"): + vocs[fid] = strings + elif fid.endswith(".rx"): + regexes[fid] = strings + + os.makedirs(f"{tx}/{lang.lower()}", exist_ok=True) + if intents: + with open(f"{tx}/{lang.lower()}/intents.json", "w") as f: + json.dump(intents, f, indent=4) + if dialogs: + with open(f"{tx}/{lang.lower()}/dialogs.json", "w") as f: + json.dump(dialogs, f, indent=4) + if vocs: + with open(f"{tx}/{lang.lower()}/vocabs.json", "w") as f: + json.dump(vocs, f, indent=4) + if regexes: + with open(f"{tx}/{lang.lower()}/regexes.json", "w") as f: + json.dump(regexes, f, indent=4) diff --git a/scripts/sync_translations.py b/scripts/sync_translations.py new file mode 100644 index 0000000..342b469 --- /dev/null +++ b/scripts/sync_translations.py @@ -0,0 +1,78 @@ +"""this script should run in every PR originated from @gitlocalize-app +TODO - before PR merge +""" + +import json +from os.path import dirname +import os + +locale = f"{dirname(dirname(__file__))}/locale" +tx = f"{dirname(dirname(__file__))}/translations" + + +for lang in os.listdir(tx): + intents = f"{tx}/{lang}/intents.json" + dialogs = f"{tx}/{lang}/dialogs.json" + vocs = f"{tx}/{lang}/vocabs.json" + regexes = f"{tx}/{lang}/regexes.json" + + if os.path.isfile(intents): + with open(intents) as f: + data = json.load(f) + for fid, samples in data.items(): + if samples: + samples = list(set([s.strip() for s in samples + if s and s.strip() != "[UNUSED]"])) # s may be None + if fid.startswith("/"): + p = f"{locale}/{lang.lower()}{fid}" + else: + p = f"{locale}/{lang.lower()}/{fid}" + os.makedirs(os.path.dirname(p), exist_ok=True) + with open(f"{locale}/{lang.lower()}/{fid}", "w") as f: + f.write("\n".join(sorted(samples))) + + if os.path.isfile(dialogs): + with open(dialogs) as f: + data = json.load(f) + for fid, samples in data.items(): + if samples: + samples = list(set([s.strip() for s in samples + if s and s.strip() != "[UNUSED]"])) # s may be None + if fid.startswith("/"): + p = f"{locale}/{lang.lower()}{fid}" + else: + p = f"{locale}/{lang.lower()}/{fid}" + os.makedirs(os.path.dirname(p), exist_ok=True) + with open(f"{locale}/{lang.lower()}/{fid}", "w") as f: + f.write("\n".join(sorted(samples))) + + if os.path.isfile(vocs): + with open(vocs) as f: + data = json.load(f) + for fid, samples in data.items(): + if samples: + samples = list(set([s.strip() for s in samples + if s and s.strip() != "[UNUSED]"])) # s may be None + if fid.startswith("/"): + p = f"{locale}/{lang.lower()}{fid}" + else: + p = f"{locale}/{lang.lower()}/{fid}" + os.makedirs(os.path.dirname(p), exist_ok=True) + with open(f"{locale}/{lang.lower()}/{fid}", "w") as f: + f.write("\n".join(sorted(samples))) + + if os.path.isfile(regexes): + with open(regexes) as f: + data = json.load(f) + for fid, samples in data.items(): + if samples: + samples = list(set([s.strip() for s in samples + if s and s.strip() != "[UNUSED]"])) # s may be None + if fid.startswith("/"): + p = f"{locale}/{lang.lower()}{fid}" + else: + p = f"{locale}/{lang.lower()}/{fid}" + os.makedirs(os.path.dirname(p), exist_ok=True) + with open(f"{locale}/{lang.lower()}/{fid}", "w") as f: + f.write("\n".join(sorted(samples))) + diff --git a/setup.py b/setup.py index 956d8aa..1de71c2 100644 --- a/setup.py +++ b/setup.py @@ -2,11 +2,12 @@ from setuptools import setup from os.path import abspath, dirname, join, isfile, isdir from os import walk +import os # Define package information SKILL_CLAZZ = "ISSLocationSkill" # Make sure it matches __init__.py class name -VERSION = "0.0.1" -URL = "https://github.com/OVOSHatchery/ovos-skill-iss-location" +VERSION = "0.1.0a1" +URL = "https://github.com/OpenVoiceOS/ovos-skill-iss-location" AUTHOR = "OpenVoiceOS" EMAIL = "jarbasai@mailfence.com" LICENSE = "Apache2.0" @@ -36,7 +37,7 @@ def get_requirements(requirements_filename: str = "requirements.txt"): # Function to find resource files def find_resource_files(): - resource_base_dirs = ("locale", "ui", "vocab", "dialog", "regex", "res") + resource_base_dirs = ("locale", "ui", "res") base_dir = abspath(dirname(__file__)) package_data = ["*.json"] for res in resource_base_dirs: diff --git a/translations/en-us/intents.json b/translations/en-us/intents.json new file mode 100644 index 0000000..a21d503 --- /dev/null +++ b/translations/en-us/intents.json @@ -0,0 +1,27 @@ +{ + "when_iss.intent": [ + "when is the I S S passing by", + "when is the space station passing by", + "when is the international space station passing by", + "international space station passing over" + ], + "where_iss.intent": [ + "where is the I S S", + "where is the space station", + "where is the international space station", + "international space station location", + "location of the space station", + "location of I S S", + "I S S location" + ], + "about.intent": [ + "about the ISS", + "about the space station", + "talk about the international space station", + "what is ISS", + "tell me about international space station", + "talk about international space station", + "tell me about international space station", + "what is the international space station" + ] +} \ No newline at end of file diff --git a/translations/en-us/vocabs.json b/translations/en-us/vocabs.json new file mode 100644 index 0000000..7fb53ad --- /dev/null +++ b/translations/en-us/vocabs.json @@ -0,0 +1,25 @@ +{ + "how_many.voc": [ + "how many", + "number", + "total" + ], + "onboard.voc": [ + "on board", + "on the", + "aboard", + "staying" + ], + "who.voc": [ + "who", + "person", + "persons", + "people" + ], + "iss.voc": [ + "ISS", + "I S S", + "space station", + "international space station" + ] +} \ No newline at end of file