Skip to content

Commit 72c6474

Browse files
author
Jonathan Koehler
committed
osm-edit conversation could work using a command entry point.
tryed using the oauth.
1 parent c7d3cad commit 72c6474

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

bot.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import logging
3-
3+
import bot_osm_edit
44
import ee_osmose
55
import osmose
66
from telegram import *
@@ -156,13 +156,15 @@ def main():
156156
# Get the dispatcher to register handlers
157157
dp = updater.dispatcher
158158

159+
editor = bot_osm_edit.ElemEditor()
159160
# on different commands - answer in Telegram
160161
dp.add_handler(CommandHandler("start", start))
161162
dp.add_handler(CommandHandler("help", help))
162163
dp.add_handler(CommandHandler('user', user_issue))
163164
dp.add_handler(CallbackQueryHandler(button))
164165
dp.add_handler(MessageHandler(Filters.location, loc_issue))
165166
dp.add_handler(CommandHandler("loc", loc_issue))
167+
dp.add_handler(editor.get_conversation())
166168

167169
# on non-command i.e message - echo the message on Telegram
168170
# dp.add_handler(MessageHandler(Filters.text, echo))

bot_osm_edit.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313

1414
class ElemEditor:
1515
def __init__(self):
16-
17-
return self.get_conversation()
16+
pass
1817

1918
def get_conversation(self):
2019
return ConversationHandler(
2120
entry_points=[CommandHandler('_edit', self.start)],
2221

2322
states={
24-
CHOOSING: [MessageHandler(Filters.regex('Tag'), self.tag),
23+
CHOOSING: [MessageHandler(Filters.regex('tag'), self.tag),
2524
MessageHandler(Filters.regex('cancel'), self.cancel)
2625
],
2726

@@ -35,11 +34,13 @@ def get_conversation(self):
3534
fallbacks=[MessageHandler(Filters.regex('^Done$'), self.cancel)]
3635
)
3736

38-
def start(self):
39-
pass
37+
def start(self, update, context):
38+
print('hello here conversation start')
39+
return CHOOSING
4040

41-
def tag(self):
42-
pass
41+
def tag(self, update, context):
42+
print('hay here is converseation Tag')
43+
return CHOOSING
4344

4445
def value(self):
4546
pass

o_auth.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ def request_token(self):
3737
self.owner_secret = fetch_response.get('oauth_token_secret')
3838
return self.owner_key, self.owner_secret
3939

40-
# Using OAuth1Session
41-
def authorize(self):
40+
def prepare_auth_url(self):
4241
authorization_url = self.oauth.authorization_url(self.base_authorization_url)
4342
print('Please go here and authorize,', authorization_url) # TODO send this message to user
44-
redirect_response = 'raw_input("Paste the full redirect URL here: ")' # TODO create socket for redirect
45-
oauth_response = self.oauth.parse_authorization_response(redirect_response)
43+
44+
# Using OAuth1Session
45+
def authorize(self, response):
46+
oauth_response = self.oauth.parse_authorization_response(response)
4647
logger.debug(oauth_response)
4748
self.verifier = oauth_response.get('oauth_verifier')
4849
return self.verifier
@@ -54,5 +55,5 @@ def access_token(self):
5455
resource_owner_key=self.owner_key,
5556
resource_owner_secret=self.owner_secret,
5657
verifier=self.verifier)
57-
oauth_tokens = self.oauth.fetch_access_token(self.acc_token_url)
58+
oauth_tokens = self.oauth.fetch_access_token(self.access_token_url)
5859

test/test_o_auth.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
import o_auth
3+
import requests
4+
5+
class MyTestCase(unittest.TestCase):
6+
auth = o_auth.Authorisation()
7+
8+
def test_something(self):
9+
owner_cr = self.auth.request_token()
10+
self.auth.prepare_auth_url()
11+
12+
def test_something(self):
13+
self.auth.authorize()
14+
15+
16+
17+
18+
19+
if __name__ == '__main__':
20+
unittest.main()

test/test_osm_api.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ def test_close_note(self):
9595

9696
def test_edit_elem(self):
9797
node = self.osmo.get_element('node', 4314858041)
98-
data = self.osmo.edit_element(node, 177967)
98+
data = self.osmo.edit_element(node, 178488)
99+
print(data)
99100

100101
def test_get_users(self):
101102
users = self.osmo.get_users([7634, 7122])

0 commit comments

Comments
 (0)