Skip to content

Commit

Permalink
code cleanup, split into multiple files
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias <[email protected]>
  • Loading branch information
call-me-matt committed Jan 26, 2025
1 parent 8d78a0e commit 0156753
Show file tree
Hide file tree
Showing 37 changed files with 821 additions and 749 deletions.
11 changes: 6 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "python",
"request": "launch",
"program": "${file}",
"args": [
"args": [
"EMAILTEST",
"en"
]
Expand All @@ -21,11 +21,12 @@
"program": "${file}",
"args": [
"--showpic",
"--twitter",
"--pic", "/home/martinix/Schreibtisch/witzige_bilder/C3wrVxcWcAEhtrU.jpg",
"WEEKLYTWTEST",
"--twitter",
"--pic",
"/home/martinix/Schreibtisch/witzige_bilder/C3wrVxcWcAEhtrU.jpg",
"WEEKLYTEST",
"en"
],
],
},
{
"name": "Python: Current File",
Expand Down
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@ Clone this repo with submodules: `git clone --recurse-submodules [email protected]:

On linux run setup.sh to get you started with all requirements for a python environment.

First you should insert your secrets into the file `configs/private/secrets/weeklysecrets.yaml`.
First you should insert your secrets into the file `configs/private/secrets/weekly.yaml`.
You would need to create that file looking something like this:

```
runnable: False
mail_user: "somegmailusername"
mail_pw: "somegmailssecretpasswort"
bluesky_TOKEN: "x3xx-xyz-xyz-abcd"
bluesky_USER: "[email protected]"
forum_KEY: "abcdef123456"
mastondon_INSTANCE: "yourinstance.social"
josm_PW: "yourJosmWikiPass"
josm_USER: "yourJosmWikiUser"
mail_PW: "somegmailssecretpasswort"
mail_USER: "somegmailusername"
mastodon_INSTANCE: "yourinstance.social"
mastodon_TOKEN: "yourMastodonDeveloperApplicationAccessToken"
matrix_USER: "@youruser:matrix.org"
matrix_BASE: "https://matrix.org"
matrix_TOKEN: "syt_tokentoken_tokentoken_token"
tw_CONSUMER_KEY: "yourTwitterConsumerKey"
tw_CONSUMER_SECRET: "yourTwitterConsumerSecretFrdsfor09512kljda98324iu21as"
matrix_USER: "@youruser:matrix.org"
telegram_TOKEN: "YourTelegramBotToken123:456"
tw_ACCESS_KEY: "123456-YourTWAccessKeyNelsonMandela4Evaaaa"
tw_ACCESS_SECRET: "YourTWAccessSecretlsdkhjkahdkjahsrwqkjhqwkjhewqkjewqh"
telegram_TOKEN: "YourTelegramBotToken123:456"
josm_user: "yourJosmWikiUser"
jsom_pw: "yourJosmWikiPass"
```
tw_BEARER_TOKEN: "AAAAAAAAAAabcdefg"
tw_CLIENT_ID: "abcdef123456xyz"
tw_CLIENT_SECRET: "123456abcdef789"
tw_CONSUMER_KEY: "0123456consumerkeyABC"
tw_CONSUMER_KEY: "yourTwitterConsumerKey"
tw_CONSUMER_SECRET: "yourTwitterConsumerSecretFrdsfor09512kljda98324iu21as"
```

Next you should define the recipients for each language in a `weekly_*.yaml` as defined in your `configs/configs.yaml`

Expand Down Expand Up @@ -78,10 +84,10 @@ It takes the same parameters as the python script but fixes PYTHONIOENCODING to

test call - for twitter
```
./runenvweekly2all.sh --twitter --pic ~/downloads/C3wrVxcWcAEhtrU.jpg --showpic "WEEKLYTWTEST" "en,de,fr"
./runenvweekly2all.sh --twitter --pic ~/downloads/abc.jpg --showpic "WEEKLYTEST" "en"
```

how to call - mail, forum, josm, telegram, mastodon and twitter
how weeklyOSM is announced:
```
./runenvweekly2all.sh --bluesky --forum --josm --mail --mastodon --matrix --telegram --pic auto --showpic "WEEKLY" "int,de,en,es,pt,tr,ru,ja,fr,it,ko,br,zh,pl,uk"
```
6 changes: 3 additions & 3 deletions configs/configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# the child might overwrite any other existing configuration with the same context name and language
# - in some cases this might be wanted behaviour - like keeping e-mail adresses secret

- private/secrets/weeklysecrets.yaml:
- private/secrets/weekly.yaml:
- weekly_base.yaml:
- weekly_int.yaml:
- private/mailto/weekly_int.yaml
Expand Down Expand Up @@ -47,5 +47,5 @@
- private/mailto/weekly_uk.yaml
- emailtest.yaml:
- private/mailto/emailtest.yaml
- private/secrets/weeklytwtest_secrets.yaml:
- weeklytwtest_en.yaml
- private/secrets/weeklytest.yaml:
- weeklytest_en.yaml
2 changes: 1 addition & 1 deletion configs/emailtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ do_mail: True # " wenn dieses auskommentiert wird, wird der paramterer "--mail"
do_twitter: False #" wenn dieses auskommentiert wird, wird der paramterer "--twitter" ignoriert und NICHT getwittert
do_mastodon: False #" wenn dieses auskommentiert wird, wird der paramterer "--mastodon" ignoriert und NICHT getootet
do_forum: False
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'Python email test'
mail_to:
- "[email protected]" # this property gets overwritten in the file with the same name found in configs/private/mailto/ folder
Expand Down
2 changes: 1 addition & 1 deletion configs/private
2 changes: 1 addition & 1 deletion configs/weekly_br.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'semanárioOSM Nº {c.post_nr} {c.daterange_str}'
tw_text: "O semanário nº {c.post_nr} está disponível em *Português do Brasil*.
Conheça as novidades do mundo #openstreetmap https://www.weeklyosm.eu/br/archives/{c.url_nr}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_cn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
tw_text: "OSM周刊第{c.post_nr}期简体中文版现已发布! 点击此处本周了解#openstreetmap #osm 社区的最新动态:https://www.weeklyosm.eu/cn/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
tw_text: "weeklyOSM Ausgabe {c.post_nr} ist nun in *Deutsch* verfügbar. Die neuesten Nachrichten aus der #openstreetmap #osm Welt https://www.weeklyosm.eu/de/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
tw_text: "weeklyOSM issue {c.post_nr} is now available in *English* the news from the #openstreetmap #osm world https://www.weeklyosm.eu/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'semanarioOSM Nº {c.post_nr} {c.daterange_str}'
tw_text: "El semanario Nº {c.post_nr} de OSM en *ESPAÑOL* está online, noticias del mundo #openstreetmap #osm - https://www.weeklyosm.eu/es/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'hebdoOSM Nº {c.post_nr} {c.daterange_str}'
tw_text: "Une semaine d'actualité #OpenStreetMap : hebdoOSM n°{c.post_nr} à lire *en français* sur https://www.weeklyosm.eu/fr/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'OSM Mingguan #{c.post_nr} {c.daterange_str}'
tw_text: "weeklyOSM edisi {c.post_nr} kini tersedia dalam Bahasa Indonesia kumpulan berita terkini mengenai #openstreetmap #osm dari seluruh penjuru dunia https://www.weeklyosm.eu/id/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
4 changes: 2 additions & 2 deletions configs/weekly_int.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ runnable: True
#do_mail: False # uncomment in order to ignore "--mail" for this language
do_twitter: False # comment to send an additional tweet in this language if "--twitter" is called (attention: shorten text to <280 chars!)
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: True # comment to send an additional post in this language if "--bluesky" is called
#do_bluesky: True # uncomment in order to ignore "--bluesky" for this language
#do_josm: False # uncomment in order to ignore "--josm" for this language
do_pin_mastodon: True
do_unpin_mastodon: True
Expand All @@ -28,7 +28,7 @@ Lisez les dernières nouvelles de l'univers #openstreetmap 🗺️ \n
Viele Neuigkeiten aus der #osm Welt 📰 \n
新一期的OSM周刊已经发布 🌏"

mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
mail_body: |
The weekly round-up of OSM news, issue # {c.post_nr},
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
tw_text: "Il numero {c.post_nr} del weeklyOSM è ora disponibile in Italiano. Le ultime notizie dal mondo #openstreetmap #osm https://www.weeklyosm.eu/it/archives/{c.url_nr}."
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
tw_text: "週刊OSM issue {c.post_nr} が公開されています。世界の #OpenStreetMap 関連ニュースはこちらからhttps://www.weeklyosm.eu/ja/archives/{c.url_nr} … どうぞご覧ください! #osmjp"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_ko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
tw_text: "#openstreetmap #osm 관련 뉴스를 전하는 주간OSM이 {c.post_nr}번째 기사를 발행했습니다! https://www.weeklyosm.eu/ko/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_pl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
tw_text: "Wydanie {c.post_nr} Tygodnika OSM już teraz dostępne w języku polskim! Najnowsze wieści ze świata #openstreetmap #osm https://www.weeklyosm.eu/pl/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_pt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'semanárioOSM Nº {c.post_nr} {c.daterange_str}'
tw_text: "O semanário nº {c.post_nr} está disponível em *português*.
Conheça as novidades do mundo #openstreetmap https://www.weeklyosm.eu/pt/archives/{c.url_nr}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
tw_text: "ЕженедельникOSM №{c.post_nr} теперь доступен на русском. Последние новости из мира #openstreetmap https://www.weeklyosm.eu/ru/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_sw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'OSMkilawiki #{c.post_nr} {c.daterange_str}'
tw_text: "OSMkilawiki, suala {c.post_nr}, sasa linapatikana kwenye mtandao katika lugha ya *Kiswahili*, kutupa muhtasari wa mambo yote yanayotokea katika ulimwengu wa #OpenStreetMap #OSM https://www.weeklyosm.eu/sw/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_tr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
tw_text: "weeklyOSM'in {c.post_nr}. hafta edisyonu, #openstreetmap #osm dünyasından haberlerle şimdi Türkçe https://www.weeklyosm.eu/tr/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_uk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'Тижневик OSM № {c.post_nr} {c.daterange_str}'
tw_text: "Тижневик OSM № {c.post_nr} тепер доступний *Українською*. Це новини зі світу #openstreetmap #osm https://www.weeklyosm.eu/uk/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
2 changes: 1 addition & 1 deletion configs/weekly_zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runnable: True
#do_mastodon: False # uncomment in order to ignore "--mastodon" for this language
do_bluesky: False # comment to send an additional post in this language if "--bluesky" is called
do_josm: False # comment to send an additional josm wiki post in this language if "--josm" is called
mail_from: "weeklyteam <{c.mail_user}>"
mail_from: "weeklyteam <{c.mail_USER}>"
mail_subject: 'weeklyOSM #{c.post_nr} {c.daterange_str}'
tw_text: "weeklyOSM {c.post_nr} 期涵蓋 #開放街圖 #osm 世界大小事,已經發佈台灣華語版本 https://www.weeklyosm.eu/zh/archives/{c.url_nr}"
bluesky_text: "{c.tw_text}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
context: 'WEEKLYTWTEST'
context: 'WEEKLYTEST'
lang: 'ko'
runnable: True
url: "https://www.weeklyosm.eu/{c.lang}/archives/{c.url_nr}/"
Expand Down
71 changes: 71 additions & 0 deletions connectors/bluesky.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import re

from atproto import (
Client as blueskyclient,
models as bluesky_models,
)


def post(self):
self.logger.info(f"...posting on bluesky...")

# log in to bluesky.social
try:
client = blueskyclient()
client.login(self.bluesky_USER, self.bluesky_TOKEN)
except Exception as e:
self.logger.error("cannot log in to bluesky.")
self.logger.error(e)
return False

# load picture
try:
if self.pic:
self.logger.debug("sending post with image")
with open(self.pic, "rb") as f:
media = f.read()
except Exception as e:
self.logger.error("cannot read picture")
self.logger.error(e)
return False

# detect any links beginning with http to make them clickable
try:
pattern = rb"https?://[^ \n\r\t]*"
matches = re.finditer(pattern, self.bluesky_text.encode("UTF-8"))
url_positions = []
for match in matches:
url_bytes = match.group(0)
url = url_bytes.decode("UTF-8")
url_positions.append((url, match.start(), match.end()))
facets = []
for link_data in url_positions:
uri, byte_start, byte_end = link_data
facets.append(
bluesky_models.AppBskyRichtextFacet.Main(
features=[bluesky_models.AppBskyRichtextFacet.Link(uri=uri)],
index=bluesky_models.AppBskyRichtextFacet.ByteSlice(
byte_start=byte_start, byte_end=byte_end
),
)
)
except Exception as e:
self.logger.warning("error detecting links, cannot make them clickable")
self.logger.error(e)
facets = []

# send post
try:
if self.pic:
client.send_image(
text=self.bluesky_text,
image=media,
image_alt="weeklyOSM title image",
facets=facets,
)
else:
client.send_post(self.bluesky_text, facets=facets)
except Exception as e:
self.logger.error("could not post to bluesky")
self.logger.error(e)
return False
Loading

0 comments on commit 0156753

Please sign in to comment.