Skip to content

Commit

Permalink
various minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmckechnie committed Dec 21, 2022
1 parent 1913a93 commit a057581
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
31 changes: 15 additions & 16 deletions bin/user/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def logerr(msg):
import requests
import json

VERSION = "0.02"
VERSION = "0.01"

if weewx.__version__ < "3":
raise weewx.UnsupportedFeature("weewx 3 is required, found %s" %
Expand All @@ -149,8 +149,6 @@ def _format(label, fmt, datum):

def _dir_to_ord(x, ordinals):
try:
huh = ordinals[int(round(x / 22.5))]
loginf("huh ordinals = %s" % huh)
return ordinals[int(round(x / 22.5))]
except (ValueError, IndexError):
pass
Expand All @@ -165,14 +163,14 @@ class Mastodon(weewx.restx.StdRESTbase):
'P: {barometer:%.3f}; R: {rain:%.3f}'

_DEFAULT_FORMAT_2 = '{station:%s\n} ' \
'Windspeed: {windSpeed:%.1f\n} ' \
'Winddir: {windDir:%03.0f\n} ' \
'Windgust: {windGust:%.1f\n} ' \
'outTemp: {outTemp:%.1f\n} ' \
'outHumidity: {outHumidity:%.2f\n} ' \
'Pressure: {barometer:%.3f\n} ' \
'Rain: {rain:%.3f\n}' \
'Time: {dateTime:%X\n}'
'Windspeed: {windSpeed:%.1f\n} ' \
'Winddir: {windDir:%03.0f\n} ' \
'Windgust: {windGust:%.1f\n} ' \
'outTemp: {outTemp:%.1f\n} ' \
'outHumidity: {outHumidity:%.2f\n} ' \
'Pressure: {barometer:%.3f\n} ' \
'Rain: {rain:%.3f\n}' \
'Date Time: {dateTime:%d %b %Y %H:%I\n}'

_DEFAULT_FORMAT_3 = '{station:%.8s}: Ws: {windSpeed:%.1f}; Wd:'

Expand Down Expand Up @@ -226,7 +224,7 @@ def __init__(self, engine, config_dict):
'mastodon_url')
if site_dict is None:
return
loginf("site_dict = %s" % site_dict)
# loginf("site_dict = %s" % site_dict)

# default the station name
site_dict.setdefault('station', engine.stn_info.location)
Expand Down Expand Up @@ -333,7 +331,7 @@ def format_toot(self, record):
if m:
oldstr = m.group(0)
fmt = m.group(1)
loginf("obs = %s" % obs)
# loginf("obs = %s" % obs)
if oldstr is not None:
if obs == 'dateTime':
if self.format_utc:
Expand All @@ -349,7 +347,7 @@ def format_toot(self, record):
newstr = fmt % record[obs]
msg = msg.replace(oldstr, newstr)
logdbg('msg: %s' % msg)
loginf('info msg: %s' % msg)
# loginf('info msg: %s' % msg)
return msg

def process_record(self, record, dummy_manager):
Expand All @@ -366,15 +364,16 @@ def process_record(self, record, dummy_manager):
ntries = 0
while ntries < self.max_tries:
ntries += 1
post = {'status': msg, 'visibility': 'direct'}
# post = {'status': msg, 'visibility': 'direct'}
post = {'status': msg}
try:
msd = requests.post(self.masturl_status,
data=post,
headers=self.mastodon_auth)
print(msd.json()['uri'])
loginf("Posted to mastodon as %s" % msg) # debug only
return

# return early so this doesn't execute - working but unfinished
media_id = json.loads(requests.post(self.masturl_media,
files={'file': open('/home/weewx/bin/user/messmatewx.png', "rb")},
data={'focus': '-1.0,1.0',
Expand Down
2 changes: 1 addition & 1 deletion install.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self):
'Mastodon': {
'access_token': 'Your access token',
'mastodon_url': 'Your Mastodon Servers URL',
'format_choice': 'None',
'format_choice': 'simple',
'post_interval': '3600'}}},
files=[('bin/user', ['bin/user/mastodon.py'])]
)
23 changes: 19 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
twitter - weewx extension that sends data to Twitter
mastodon - weewx extension that sends data to Mastodon
Copyright 2014-2020 Matthew Wall
Distributed under the terms of the GNU Public License (GPLv3)

Copyright Glenn McKechnie 2022 (mastodon changes)

===============================================================================

Currently - this is in ALPHA - or a vague handwaving BETA condition.

You're more than welcome (encouraged) to download and use it - then
report back on any crashes / bugs / enhancements that may be required.

Just remember that the pieces are always yours.

Otherwise - wait a while... About the length of a piece of string
while. :-)

See the comments in mastodon.py on how to set this up - get a key etc.


===============================================================================
Pre-requisites

Geberate an access token on your mastodon server of choice
Generate an access token on your mastodon server of choice



Expand All @@ -16,7 +31,7 @@ Installation instructions

1) download

wget -O weewx-mastodon.zip https://github.com/matthewwall/weewx-mastodon/archive/main.zip
wget -O weewx-mastodon.zip https://github.com/glennmckechnie/weewx-mastodon/archive/refs/heads/main.zip

2) run the installer:

Expand All @@ -40,4 +55,4 @@ sudo /etc/init.d/weewx start
===============================================================================
Options

For configuration options and details, see the comments in twitter.py
For configuration options and details, see the comments in mastodon.py

0 comments on commit a057581

Please sign in to comment.