-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
75 lines (57 loc) · 1.43 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import json
import pandas as pd
from random import seed
from random import randint
import datetime
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from flask import Flask, request
"""
{
"attachments": [],
"avatar_url": "http://i.groupme.com/123456789",
"created_at": 1302623328,
"group_id": "1234567890",
"id": "1234567890",
"name": "John",
"sender_id": "12345",
"sender_type": "user",
"source_guid": "GUID",
"system": false,
"text": "Hello world ☃☃",
"user_id": "1234567890"
}"""
app = Flask(__name__)
df = pd.read_csv('quotes.csv')
@app.route('/', methods=['POST'])
def webhook():
data = request.get_json()
if data['text'] == 'inspireme':
r = randint(0,1664)
auth = str(df.iloc[r][0])
quote = str(df.iloc[r][1])
msg = quote + " - " + auth
send_message(msg)
return "ok", 200
"""
@app.route('/', methods=['POST'])
def webhook():
data = request.get_json()
# We don't want to reply to ourselves!
if data['name'] != 'test':
msg = '{}, you sent "{}".'.format(data['name'], data['text'])
send_message(msg)
return "ok", 200
"""
def send_message(msg):
url = 'https://api.groupme.com/v3/bots/post'
data = {
'bot_id' : os.getenv('GROUPME_BOT_ID'),
'text' : msg,
}
request = Request(url, urlencode(data).encode())
json = urlopen(request).read().decode()
def log(msg):
print(str(msg))
sys.stdout.flush()