Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,14 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
print(response.json())
|
13 |
-
except requests.exceptions.RequestException as e:
|
14 |
-
print(f"An error occurred while sending the message: {e}")
|
15 |
-
|
16 |
-
def handle_message(message):
|
17 |
-
chat_id = message['chat']['id']
|
18 |
-
text = message['text']
|
19 |
-
if text == '/start':
|
20 |
-
send_message(chat_id, 'Hi')
|
21 |
-
|
22 |
-
def main():
|
23 |
-
offset = None
|
24 |
-
while True:
|
25 |
-
try:
|
26 |
-
url = f'https://api.telegram.org/bot{bot_token}/getUpdates'
|
27 |
-
params = {'offset': offset}
|
28 |
-
response = requests.get(url, params=params, timeout=5, dns='8.8.8.8')
|
29 |
-
response.raise_for_status()
|
30 |
-
data = response.json()
|
31 |
-
if data['ok']:
|
32 |
-
for update in data['result']:
|
33 |
-
offset = update['update_id'] + 1
|
34 |
-
if 'message' in update:
|
35 |
-
handle_message(update['message'])
|
36 |
-
except requests.exceptions.RequestException as e:
|
37 |
-
print(f"An error occurred while getting updates: {e}")
|
38 |
-
time.sleep(1)
|
39 |
|
40 |
if __name__ == '__main__':
|
41 |
-
|
|
|
1 |
+
from flask import Flask, request
|
2 |
+
import geocoder
|
3 |
|
4 |
+
app = Flask(__name__)
|
5 |
|
6 |
+
@app.route('/')
|
7 |
+
def index():
|
8 |
+
user_ip = request.remote_addr
|
9 |
+
location = geocoder.ip(user_ip).city
|
10 |
+
# Do something with the user's location
|
11 |
+
return f"Your location is: {location}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
if __name__ == '__main__':
|
14 |
+
app.run()
|