Skip to content

Commit

Permalink
Make use of service_name more consistent
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Aug 23, 2018
1 parent 76ce5a9 commit ae83eab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.8.0'
_release = '1577'
_commit = 'fb949be'
_release = '1578'
_commit = '76ce5a9'
21 changes: 11 additions & 10 deletions src/pywws/service/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,17 @@
import pywws.service

__docformat__ = "restructuredtext en"
service_name = os.path.splitext(os.path.basename(__file__))[0]
logger = logging.getLogger(__name__)


class ToService(pywws.service.FileService):
logger = logger
service_name = 'mastodon'
service_name = service_name

def __init__(self, context):
# check config
handle = context.params.get(self.service_name, 'handle', '')
handle = context.params.get(service_name, 'handle', '')
if not handle:
raise RuntimeError('No user handle specified in weather.ini')
# get default character encoding of template output
Expand All @@ -183,9 +184,9 @@ def __init__(self, context):

@contextmanager
def session(self):
handle = self.context.params.get(self.service_name, 'handle')
handle = self.context.params.get(service_name, 'handle')
api_base_url = handle.split('@')[-1]
access_token = self.context.params.get(self.service_name, 'access_token')
access_token = self.context.params.get(service_name, 'access_token')
if not access_token:
raise RuntimeError('Authentication data not found')
yield Mastodon(access_token=access_token, api_base_url=api_base_url)
Expand Down Expand Up @@ -214,16 +215,16 @@ def register(self):
import webbrowser

# get user handle
handle = self.context.params.get(self.service_name, 'handle')
handle = self.context.params.get(service_name, 'handle')
api_base_url = handle.split('@')[-1]
# get client data
client_id = self.context.params.get(self.service_name, 'client_id')
client_secret = self.context.params.get(self.service_name, 'client_secret')
client_id = self.context.params.get(service_name, 'client_id')
client_secret = self.context.params.get(service_name, 'client_secret')
if (not client_id) or (not client_secret):
client_id, client_secret = Mastodon.create_app(
'pywws', scopes=['write'], api_base_url=api_base_url)
self.context.params.set(self.service_name, 'client_id', client_id)
self.context.params.set(self.service_name, 'client_secret', client_secret)
self.context.params.set(service_name, 'client_id', client_id)
self.context.params.set(service_name, 'client_secret', client_secret)
# create api
api = Mastodon(client_id=client_id, client_secret=client_secret,
api_base_url=api_base_url)
Expand All @@ -240,7 +241,7 @@ def register(self):
code = code.strip()
# log in
access_token = api.log_in(code=code, scopes=['write'])
self.context.params.set(self.service_name, 'access_token', access_token)
self.context.params.set(service_name, 'access_token', access_token)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion src/pywws/service/openweathermap.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def register(self):
for key in 'id', 'ID':
if key in rsp:
self.context.params.set(
self.service_name, 'station id', rsp[key])
service_name, 'station id', rsp[key])


if __name__ == "__main__":
Expand Down
15 changes: 8 additions & 7 deletions src/pywws/service/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
import pywws.service

__docformat__ = "restructuredtext en"
service_name = os.path.splitext(os.path.basename(__file__))[0]
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -251,7 +252,7 @@ def post(self, status, media):

class ToService(pywws.service.FileService):
logger = logger
service_name = 'twitter'
service_name = service_name

def __init__(self, context):
# get default character encoding of template output
Expand All @@ -263,12 +264,12 @@ def __init__(self, context):
@contextmanager
def session(self):
# get parameters
key = self.context.params.get(self.service_name, 'key')
secret = self.context.params.get(self.service_name, 'secret')
key = self.context.params.get(service_name, 'key')
secret = self.context.params.get(service_name, 'secret')
if (not key) or (not secret):
raise RuntimeError('Authentication data not found')
latitude = self.context.params.get(self.service_name, 'latitude')
longitude = self.context.params.get(self.service_name, 'longitude')
latitude = self.context.params.get(service_name, 'latitude')
longitude = self.context.params.get(service_name, 'longitude')
# open API
if twitter:
yield PythonTwitterHandler(key, secret, latitude, longitude, 40)
Expand Down Expand Up @@ -337,9 +338,9 @@ def register(self):
content = content.decode('utf-8')
access_token = dict(parse_qsl(content))
self.context.params.set(
self.service_name, 'key', access_token['oauth_token'])
service_name, 'key', access_token['oauth_token'])
self.context.params.set(
self.service_name, 'secret', access_token['oauth_token_secret'])
service_name, 'secret', access_token['oauth_token_secret'])


if __name__ == "__main__":
Expand Down

0 comments on commit ae83eab

Please sign in to comment.