Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.11 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import QIWI
  3. import re
  4. import phonelib
  5. import User
  6. import time
  7. import datetime
  8. import os
  9. import sqlite3 as lite
  10. import MySQLdb
  11.  
  12. def get_accountid(account_id):
  13. account_id = account_id.encode('utf8')
  14. try:
  15. db = MySQLdb.connect(host='62.109.17.46', user="utmpay",passwd="utmpay15",db="UTM5")
  16. except MySQLdb.Error, e:
  17. print("[ERROR] %d: %s\n" % (e.args[0], e.args[1]))
  18. sys.exit(255)
  19.  
  20. 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
  21. try:
  22. cursor = db.cursor()
  23. cursor.execute(sql)
  24. result = cursor.fetchone()
  25. except MySQLdb.Error, e:
  26. print("[ERROR] %d: %s\n" % (e.args[0], e.args[1]))
  27. if result is not None:
  28. return result[0]
  29.  
  30. def add_payment_ext_utm(sys_name, accid, amount, comment, date, mid):
  31. try:
  32. db = MySQLdb.connect(host = '62.109.17.46', user="utmpay",passwd="utmpay15",db="IUTM")
  33. except MySQLdb.Error, e:
  34. print("[ERROR] %d: %s\n" % (e.args[0], e.args[1]))
  35. sys.exit(255)
  36. 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)
  37. try:
  38. cursor = db.cursor()
  39. cursor.execute(sql)
  40. except MySQLdb.Error, e:
  41. print("[ERROR] %d: %s\n" % (e.args[0], e.args[1]))
  42.  
  43.  
  44. def sendmail(to_addr,subj,text):
  45. SENDMAIL = "/usr/sbin/sendmail" # sendmail location
  46. import os
  47. p = os.popen("%s -t" % SENDMAIL, "w")
  48. p.write("To: %s \n" % to_addr)
  49. p.write("From: notify@internet96.ru\n")
  50. p.write("Subject: %s\n" % subj)
  51. p.write("\n") # blank line separating headers from body
  52. p.write("%s\n" % text)
  53. sts = p.close()
  54. if sts != 0:
  55. print "Sendmail exit status", sts
  56.  
  57. user = "79220243333"
  58. token = "7e98b38639f9d689a81d9138e3c6d0a0"
  59. udid = "EA4HSGZD8T795PN7"
  60.  
  61. q = QIWI.QIWI(user,token,udid)
  62.  
  63. os.environ['TZ'] = 'Europe/Moscow'
  64. time.tzset()
  65.  
  66. f = open('/netup/prov/last_check.lck', 'r')
  67. try:
  68. date_str = f.readline()
  69. last_id = f.readline()
  70. date = time.strptime(date_str, '%d.%m.%Y %H:%M:%S\n')
  71. print "Last check was: %sLast id:%s" % (date_str,last_id)
  72. except Exception, e:
  73. print "no lock file found"
  74.  
  75. f.close()
  76.  
  77. con = lite.connect('/netup/prov/trans.db',isolation_level=None)
  78. cur = con.cursor()
  79.  
  80. for transcation in q.GetIncome("today"):
  81. print "%s Amount: %s income %s\t" % (time.asctime(transcation.time), transcation.amount,transcation.income)
  82. cur.execute('SELECT Id from Trans WHERE Id = %s' % transcation.id)
  83. tax = phonelib.norm_tax(transcation.comment)
  84. Id = cur.fetchone()
  85.  
  86. if transcation.income and not Id:
  87. if tax is not None:
  88. #-- add 31072018
  89. match = re.match('^05\d{3}$', tax)
  90. if match:
  91. account_id = get_accountid(tax)
  92. if account_id is not None:
  93. #need change
  94. date = time.strftime('%Y-%m-%d %H:%M:%S', transcation.time)
  95. add_payment_ext_utm('QIWI Payment', account_id, int(transcation.amount), transcation.comment, date, '104')
  96. print "QIWI Payment EXT => account_id: %s, amount: %s, comment: %s, time: %s" % (account_id, int(transcation.amount), transcation.comment, date)
  97. #-- end 31072018
  98.  
  99. cur.execute("INSERT INTO Trans VALUES(%s, '%s', 'True', %s, '%s')" % (transcation.id,transcation.time,transcation.amount,transcation.comment))
  100. phone = phonelib.norm_phone(transcation.comment)
  101. tax = phonelib.norm_tax(transcation.comment)
  102. if phone or tax:
  103. if match:
  104. user_id = phonelib.find_user_with_phone(phone,h='62.109.17.46',u="utmpay",pwd="utmpay15",db="UTM5")
  105. user_id_tax = phonelib.find_user_with_tax(tax,h='62.109.17.46',u="utmpay",pwd="utmpay15",db="UTM5")
  106. else:
  107. user_id = phonelib.find_user_with_phone(phone)
  108. user_id_tax = phonelib.find_user_with_tax(tax)
  109. if user_id:
  110. if match:
  111. user = User.User(user_id, 1)
  112. else:
  113. user = User.User(user_id, 0)
  114. sendmail("alexnet9220343131@yandex.ru","QIWI Payment Username: %s \tComment: %s Amount %s" % (user.login, transcation.comment,transcation.amount),"")
  115. sendmail("notify@internet96.ru","QIWI Payment Username: %s \tComment: %s Amount %s" % (user.login, transcation.comment,transcation.amount),"")
  116. if match:
  117. balance = user.GetBalance(1)
  118. else:
  119. balance = user.GetBalance(0)
  120. # if balance < 0:
  121. # user.Pay(abs(balance))
  122. user.Pay(transcation.amount)
  123. user.ChangeInternetStatus("on")
  124. print "Username: %s \tComment: %s" % (user.login, transcation.comment)
  125. elif user_id_tax:
  126. print tax
  127. print user_id_tax
  128. if match:
  129. user = User.User(user_id_tax, 1)
  130. else:
  131. user = User.User(user_id_tax, 0)
  132. print user.login
  133. sendmail("alexnet9220343131@yandex.ru","QIWI Payment Username: %s \tComment: %s Amount %s" % (user.login, transcation.comment,transcation.amount),"")
  134. sendmail("notify@internet96.ru","QIWI Payment Username: %s \tComment: %s Amount %s" % (user.login, transcation.comment,transcation.amount),"")
  135. if match:
  136. balance = user.GetBalance(1)
  137. else:
  138. balance = user.GetBalance(0)
  139. # if balance < 0:
  140. # user.Pay(abs(balance))
  141. user.Pay(transcation.amount)
  142. user.ChangeInternetStatus("on")
  143. print "Username: %s \tComment: %s" % (user.login, transcation.comment)
  144. else:
  145. sendmail("alexnet9220343131@yandex.ru","QIWI Payment Username: Unknown \tComment: %s Amount %s" % (transcation.comment,transcation.amount),"")
  146. sendmail("notify@internet96.ru","QIWI Payment Username: Unknown \tComment: %s Amount %s" % (transcation.comment,transcation.amount),"")
  147. print "Username: Unknown \tComment: %s" % transcation.comment
  148. else:
  149. sendmail("alexnet9220343131@yandex.ru","QIWI Payment Username: Unknown \tComment: %s Amount %s" % (transcation.comment,transcation.amount),"")
  150. sendmail("notify@internet96.ru","QIWI Payment Username: Unknown \tComment: %s Amount %s" % (transcation.comment,transcation.amount),"")
  151. print "Username: Unknown \tComment: %s" % transcation.comment
  152. elif not transcation.income and transcation.time > date:
  153. print "Expenses! Comment: %s" % transcation.comment
  154. con.commit()
  155.  
  156. f = open('/netup/prov/last_check.lck', 'w')
  157. f.write(datetime.datetime.now().strftime("%d.%m.%Y %H:%M:%S"))
  158. f.write("\n")
  159. #f.write(str(last_id))
  160. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement