Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import QIWI
- import re
- import phonelib
- import User
- import time
- import datetime
- import os
- import sqlite3 as lite
- import MySQLdb
- def get_accountid(account_id):
- account_id = account_id.encode('utf8')
- try:
- db = MySQLdb.connect(host='62.109.17.46', user="utmpay",passwd="utmpay15",db="UTM5")
- except MySQLdb.Error, e:
- print("[ERROR] %d: %s\n" % (e.args[0], e.args[1]))
- sys.exit(255)
- sql = """SELECT account_id FROM service_links WHERE user_id = (SELECT id FROM users WHERE tax_number = '%s' and is_deleted=0) LIMIT 1;""" % account_id
- try:
- cursor = db.cursor()
- cursor.execute(sql)
- result = cursor.fetchone()
- except MySQLdb.Error, e:
- print("[ERROR] %d: %s\n" % (e.args[0], e.args[1]))
- if result is not None:
- return result[0]
- def add_payment_ext_utm(sys_name, accid, amount, comment, date, mid):
- try:
- db = MySQLdb.connect(host = '62.109.17.46', user="utmpay",passwd="utmpay15",db="IUTM")
- except MySQLdb.Error, e:
- print("[ERROR] %d: %s\n" % (e.args[0], e.args[1]))
- sys.exit(255)
- sql = """INSERT INTO payment (system, mid, aid, sum, komment, date, snd, tst) values ('%s', '%s','%s','%s','%s','%s',0,0)""" % (sys_name, mid, accid, amount, comment, date)
- try:
- cursor = db.cursor()
- cursor.execute(sql)
- except MySQLdb.Error, e:
- print("[ERROR] %d: %s\n" % (e.args[0], e.args[1]))
- def sendmail(to_addr,subj,text):
- SENDMAIL = "/usr/sbin/sendmail" # sendmail location
- import os
- p = os.popen("%s -t" % SENDMAIL, "w")
- p.write("To: %s \n" % to_addr)
- p.write("From: notify@internet96.ru\n")
- p.write("Subject: %s\n" % subj)
- p.write("\n") # blank line separating headers from body
- p.write("%s\n" % text)
- sts = p.close()
- if sts != 0:
- print "Sendmail exit status", sts
- user = "79220243333"
- token = "7e98b38639f9d689a81d9138e3c6d0a0"
- udid = "EA4HSGZD8T795PN7"
- q = QIWI.QIWI(user,token,udid)
- os.environ['TZ'] = 'Europe/Moscow'
- time.tzset()
- f = open('/netup/prov/last_check.lck', 'r')
- try:
- date_str = f.readline()
- last_id = f.readline()
- date = time.strptime(date_str, '%d.%m.%Y %H:%M:%S\n')
- print "Last check was: %sLast id:%s" % (date_str,last_id)
- except Exception, e:
- print "no lock file found"
- f.close()
- con = lite.connect('/netup/prov/trans.db',isolation_level=None)
- cur = con.cursor()
- for transcation in q.GetIncome("today"):
- print "%s Amount: %s income %s\t" % (time.asctime(transcation.time), transcation.amount,transcation.income)
- cur.execute('SELECT Id from Trans WHERE Id = %s' % transcation.id)
- tax = phonelib.norm_tax(transcation.comment)
- Id = cur.fetchone()
- if transcation.income and not Id:
- if tax is not None:
- #-- add 31072018
- match = re.match('^05\d{3}$', tax)
- if match:
- account_id = get_accountid(tax)
- if account_id is not None:
- #need change
- date = time.strftime('%Y-%m-%d %H:%M:%S', transcation.time)
- add_payment_ext_utm('QIWI Payment', account_id, int(transcation.amount), transcation.comment, date, '104')
- print "QIWI Payment EXT => account_id: %s, amount: %s, comment: %s, time: %s" % (account_id, int(transcation.amount), transcation.comment, date)
- #-- end 31072018
- cur.execute("INSERT INTO Trans VALUES(%s, '%s', 'True', %s, '%s')" % (transcation.id,transcation.time,transcation.amount,transcation.comment))
- phone = phonelib.norm_phone(transcation.comment)
- tax = phonelib.norm_tax(transcation.comment)
- if phone or tax:
- if match:
- user_id = phonelib.find_user_with_phone(phone,h='62.109.17.46',u="utmpay",pwd="utmpay15",db="UTM5")
- user_id_tax = phonelib.find_user_with_tax(tax,h='62.109.17.46',u="utmpay",pwd="utmpay15",db="UTM5")
- else:
- user_id = phonelib.find_user_with_phone(phone)
- user_id_tax = phonelib.find_user_with_tax(tax)
- if user_id:
- if match:
- user = User.User(user_id, 1)
- else:
- user = User.User(user_id, 0)
- sendmail("alexnet9220343131@yandex.ru","QIWI Payment Username: %s \tComment: %s Amount %s" % (user.login, transcation.comment,transcation.amount),"")
- sendmail("notify@internet96.ru","QIWI Payment Username: %s \tComment: %s Amount %s" % (user.login, transcation.comment,transcation.amount),"")
- if match:
- balance = user.GetBalance(1)
- else:
- balance = user.GetBalance(0)
- # if balance < 0:
- # user.Pay(abs(balance))
- user.Pay(transcation.amount)
- user.ChangeInternetStatus("on")
- print "Username: %s \tComment: %s" % (user.login, transcation.comment)
- elif user_id_tax:
- print tax
- print user_id_tax
- if match:
- user = User.User(user_id_tax, 1)
- else:
- user = User.User(user_id_tax, 0)
- print user.login
- sendmail("alexnet9220343131@yandex.ru","QIWI Payment Username: %s \tComment: %s Amount %s" % (user.login, transcation.comment,transcation.amount),"")
- sendmail("notify@internet96.ru","QIWI Payment Username: %s \tComment: %s Amount %s" % (user.login, transcation.comment,transcation.amount),"")
- if match:
- balance = user.GetBalance(1)
- else:
- balance = user.GetBalance(0)
- # if balance < 0:
- # user.Pay(abs(balance))
- user.Pay(transcation.amount)
- user.ChangeInternetStatus("on")
- print "Username: %s \tComment: %s" % (user.login, transcation.comment)
- else:
- sendmail("alexnet9220343131@yandex.ru","QIWI Payment Username: Unknown \tComment: %s Amount %s" % (transcation.comment,transcation.amount),"")
- sendmail("notify@internet96.ru","QIWI Payment Username: Unknown \tComment: %s Amount %s" % (transcation.comment,transcation.amount),"")
- print "Username: Unknown \tComment: %s" % transcation.comment
- else:
- sendmail("alexnet9220343131@yandex.ru","QIWI Payment Username: Unknown \tComment: %s Amount %s" % (transcation.comment,transcation.amount),"")
- sendmail("notify@internet96.ru","QIWI Payment Username: Unknown \tComment: %s Amount %s" % (transcation.comment,transcation.amount),"")
- print "Username: Unknown \tComment: %s" % transcation.comment
- elif not transcation.income and transcation.time > date:
- print "Expenses! Comment: %s" % transcation.comment
- con.commit()
- f = open('/netup/prov/last_check.lck', 'w')
- f.write(datetime.datetime.now().strftime("%d.%m.%Y %H:%M:%S"))
- f.write("\n")
- #f.write(str(last_id))
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement