main.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import psycopg2 as pg
  2. from sshtunnel import SSHTunnelForwarder
  3. from config import host, user, password, db_name, jid, jidpassword, port, SSH_H
  4. from multiprocessing import connection
  5. from dateutil import parser
  6. import datetime, time
  7. import xmpp
  8. #Проверка соединения и само соединение
  9. try:
  10. print('Connecting to the PostgreSQL Database...')
  11. ssh_tunnel = SSHTunnelForwarder(
  12. (SSH_H, 334),
  13. ssh_username = "artem_valiakhmetov",
  14. ssh_private_key = 'D:/keys/home/.ssh/id_rsa ',
  15. ssh_private_key_password = '',
  16. remote_bind_address = ("localhost", 5432)
  17. )
  18. ssh_tunnel.start()
  19. print("Tunnel start!")
  20. conn = pg.connect(
  21. host = "localhost",
  22. port = ssh_tunnel.local_bind_port,
  23. user = "postgres",
  24. password = "",
  25. database = "sharixdrive"
  26. )
  27. print("Success ssh connect!")
  28. print("Successfully connection...")
  29. except Exception as ex:
  30. print("Error connection to database...")
  31. print(ex)
  32. def add_client_to_metaservice(user_id, ticket_status, id_metaservice):
  33. with conn.cursor() as cursor:
  34. insert_into_client_to_metaservice = "INSERT INTO client (user_id, requirements, status, ticket_status, id_metaservice, is_global, is_visible) VALUES (%s,'sgGshHz','A',%s,%s,'t','f')"
  35. val = [user_id, ticket_status, id_metaservice]
  36. cursor.execute(insert_into_client_to_metaservice)
  37. conn.commit()
  38. def change_client_visibility(user_id, id_metaservice, is_visible):
  39. with conn.cursor() as cursor:
  40. update_client_visibility = "UPDATE client SET is_visible = %s WHERE user_id = %s AND id_metaservice = %s"
  41. val = [is_visible, user_id, id_metaservice]
  42. cursor.execute(update_client_visibility)
  43. conn.commit()
  44. def change_client_globality(user_id, id_metaservice, is_global):
  45. with conn.cursor() as cursor:
  46. update_client_globality = "UPDATE client SET is_global = %s WHERE user_id = %s AND id_metaservice = %s"
  47. val = [is_global, user_id, id_metaservice]
  48. cursor.execute(update_client_globality)
  49. conn.commit()
  50. def check_client_status():
  51. def find_client_tickets():
  52. def add_provider_to_metaservice(id, id_metaservice):
  53. with conn.cursor() as cursor:
  54. insert_into_provider_to_metaservice = "INSERT INTO provider (type, id_company, user_id, id_metaservice, requirements, status, ticket_status, is_global, is_visible) VALUES (%s, %s, %s, %s, %s, status, ticket_status, is_global, is_visible)"
  55. val = [type, id_company, user_id, id_metaservice, requirements, status, ticket_status, is_global, is_visible]
  56. cursor.execute(insert_into_provider_to_metaservice)
  57. conn.commit()
  58. def change_provider_visibility(id, id_metaservice, is_visible):
  59. with conn.cursor() as cursor:
  60. update_provider_visibility = "UPDATE provider SET is_visible = %s WHERE id = %s AND id_metaservice = %s"
  61. val = [is_visible, id, id_metaservice]
  62. cursor.execute(update_provider_visibility)
  63. conn.commit()
  64. def change_provider_globality(id, id_metaservice, is_global):
  65. with conn.cursor() as cursor:
  66. update_provider_visibility = "UPDATE provider SET is_global = %s WHERE id = %s AND id_metaservice = %s"
  67. val = [is_global, id, id_metaservice]
  68. cursor.execute(update_provider_visibility)
  69. conn.commit()