Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. файл db
  2. try:
  3. db = psycopg2.connect("dbname='domain_expire' user='test' password='matt17'")
  4. cursor = db.cursor()
  5. cursor.execute("CREATE TABLE domains (id serial PRIMARY KEY, "
  6. "dname varchar(255) UNIQUE NULL, "
  7. "period integer DEFAULT 0,"
  8. "status integer DEFAULT 0);")
  9.  
  10. cursor.execute("CREATE TABLE sessions (id serial PRIMARY KEY, "
  11. "started timestamp, "
  12. "finished timestamp, "
  13. "status integer DEFAULT 0);")
  14.  
  15. cursor.execute("CREATE TABLE result (id serial PRIMARY KEY, "
  16. "session_id integer references sessions(id), "
  17. "domain_id integer references domains(id), "
  18. "dmn_created timestamp, "
  19. "dmn_updated timestamp, "
  20. "dmn_expired timestamp, "
  21. "answer varchar(255) NULL, "
  22. "checked integer DEFAULT 0);")
  23.  
  24. cursor.execute("CREATE TABLE statuses (id serial PRIMARY KEY, "
  25. "name text UNIQUE NULL);")
  26.  
  27. cursor.execute("CREATE TABLE result_status (result_id integer references result(id), "
  28. "status_id integer references statuses(id));")
  29.  
  30. db.commit()
  31. cursor.close()
  32. except psycopg2.Error as err:
  33. print("Connection error: {}".format(err))
  34.  
  35.  
  36. def insert_statuses(status):
  37. try:
  38. cursor.execute("INSERT INTO statuses (name) VALUES ({});".format(status))
  39. db.commit()
  40. cursor.close()
  41. except psycopg2.Error as err:
  42. print(err.pgerror)
  43. print(err.diag.message_primary)
  44. print("Connection error: {}".format(err))
  45.  
  46. def select_statuses(get_params, column, value):
  47. try:
  48. cursor.execute("SELECT {0} FROM statuses WHERE {1}={2};".format(get_params, column, value))
  49. status = cursor.fetchall()
  50. if status is not None:
  51. return status
  52. else:
  53. return False
  54. db.commit()
  55. cursor.close()
  56. except psycopg2.Error as err:
  57. print("Connection error: {}".format(err))
  58.  
  59. файл worker
  60. def get_whois():
  61. try:
  62. url = requests.get("https://api.ps.kz/kzdomain/domain-whois?username=name&password=pass&input_format=json&output_format=json&input_data={%20%22dname%22:%20%22kapital.kz%22,%20%22contact_whois%22:%201}")
  63. if url.status_code == 200:
  64. whois = url.json()
  65. else:
  66. print(url.status_code)
  67.  
  68. if whois is not None:
  69. for status in whois["answer"]["statuses"]["status"]:
  70. status_id = db.select_statuses(get_params='id', column='name', value='status')
  71. if status_id is None:
  72. db.insert_statuses(status)
  73.  
  74. выводит
  75. Connection error: ОШИБКА: текущая транзакция прервана, команды до конца блока транзакции игнорируются
  76.  
  77. ОШИБКА: текущая транзакция прервана, команды до конца блока транзакции игнорируются
  78.  
  79. текущая транзакция прервана, команды до конца блока транзакции игнорируются
  80. Connection error: ОШИБКА: текущая транзакция прервана, команды до конца блока транзакции игнорируются
  81.  
  82. Connection error: ОШИБКА: текущая транзакция прервана, команды до конца блока транзакции игнорируются
  83.  
  84. ОШИБКА: текущая транзакция прервана, команды до конца блока транзакции игнорируются
  85.  
  86. текущая транзакция прервана, команды до конца блока транзакции игнорируются
  87. Connection error: ОШИБКА: текущая транзакция прервана, команды до конца блока транзакции игнорируются
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement