-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsms-ru.py
52 lines (45 loc) · 1.22 KB
/
sms-ru.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
#!/usr/bin/python3
import sys
import os
import requests
import time
import mysql.connector
import argparse
def myloading():
cfgpath = "config-sms-ru.txt"
fconf = open(cfgpath, 'r')
tconf = fconf.read()
fconf.close()
conf_list = tconf.split('\n')
phone = conf_list[0]
apikey = conf_list[1]
return conf_list
def send_message(msg_params):
sms_url = 'https://sms.ru/sms/send?api_id=key&to=number&msg=message&json=1'
sms_url = sms_url.replace('number', msg_params[0])
sms_url = sms_url.replace('key', msg_params[1])
message = 'there is new data in '+msg_params[2]+'!'
#print(message)
sms_url = sms_url.replace('message', message)
# TODO try block. Sometimes SMS.RU get stuck
sms_response = requests.get(sms_url)
sms_response = str(sms_response)
succesCodeIndex = sms_response.find('200')
if succesCodeIndex != -1:
returnAnswer = "OK"
else:
returnAnswer = "fail"
print(returnAnswer)
def mainf():
parser = argparse.ArgumentParser()
parser.add_argument("db", help="database name", type=str)
args = parser.parse_args()
dbname = args.db
my_params = myloading()
my_params.append(dbname)
send_message(my_params)
if __name__ == "__main__":
mainf()
else:
main(f)
#print("the program is being imported into another module")