Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. import fdb
  2. #import xlwt
  3. import xlsxwriter
  4.  
  5.  
  6. def output(filename, list1, list2):
  7. # Create an new Excel file and add a worksheet.
  8. workbook = xlsxwriter.Workbook(filename + '.xlsx')
  9. worksheet = workbook.add_worksheet()
  10.  
  11. # Write some numbers, with row/column notation.
  12. for i in range(len(list1)):
  13. decoded_str = list1[i].decode("windows-1252")
  14. encoded_str = decoded_str.encode('ascii', 'ignore')
  15. worksheet.write_string(i, 0, encoded_str)
  16. worksheet.write_string(i, 1, list2[i].decode('utf-8'))
  17.  
  18. workbook.close()
  19.  
  20. def get_users(date_1,date_2):
  21. mon_con = fdb.connect(dsn="cp_monitoring.gdb",user='SYSDBA',password='masterke')
  22. cur = mon_con.cursor()
  23. cur.execute("select username from users_activity where logon_date between '{0}' and '{1}'".format(date_1, date_2))
  24. res = cur.fetchall()
  25. #for elem in res:
  26. # print elem
  27. cur.close()
  28. mon_con.close()
  29. return res
  30.  
  31. def get_firms(user_name):
  32. curr_con = fdb.connect(dsn="curr.gdb",user='SYSDBA',password='masterke')
  33. cur = curr_con.cursor()
  34. cur.execute("select firmid from users where id='{0}'".format(user_name))
  35. res = cur.fetchall()
  36. #for elem in res:
  37. # print elem
  38. cur.close()
  39. curr_con.close()
  40. if len(res):
  41. s = ''.join(res[0])
  42. return s
  43. else:
  44. return ''
  45.  
  46. #def get_status(user_idd):
  47. # status = ' '
  48. # mon_con = fdb.connect(dsn="curr.gdb",user='SYSDBA',password='masterke')
  49. # cur = mon_con.cursor()
  50. #cur.execute("select id from firms where user_id <> '{0}'".format(user_idd))
  51. #res = cur.fetchall()
  52.  
  53. #cur.close()
  54. #mon_con.close()
  55. def get_all_firms():
  56. curr_con = fdb.connect(dsn="curr.gdb",user='SYSDBA',password='masterke')
  57. cur = curr_con.cursor()
  58. cur.execute("select id from firms order by id")
  59. res = cur.fetchall()
  60. cur.close()
  61. curr_con.close()
  62. return res
  63.  
  64. def finish(selected_firmid, all_firmid):
  65. index = 0
  66. print len(selected_firmid)
  67. firms = list()
  68. activities = list()
  69. for elem in all_firmid:
  70. s = ''.join(elem)
  71. firms.append(s)
  72. if (s in selected_firmid):
  73. activities.append('active')
  74. #print ( s + ' active')
  75. else:
  76. activities.append('inactive')
  77. #print ( s + ' inactive')
  78. output('UserActivities', firms, activities)
  79. #if (index < len(selected_firmid)):
  80. # s1 = selected_firmid[index]#''.join(selected_firmid[index])
  81. # s2 = ''.join(elem)
  82. # if
  83. #if(s1 == s2):
  84. # index+=1
  85. # print '----'
  86. # print s1
  87. # print s2
  88. # print ( s1 + ' active')
  89. #else:
  90. # print ( str(elem) + ' inactive')
  91.  
  92.  
  93. if __name__ == '__main__':
  94. user_id = get_users('12.04.2018','12.04.2018')
  95. selected_firmid = list()
  96. for elem in user_id:
  97. firm_id = get_firms(elem[0])
  98. if firm_id != '':
  99. selected_firmid.append(firm_id)
  100. selected_firmid.sort()
  101. selected_firmid = list(set(selected_firmid))
  102. all_1=get_all_firms()
  103. all_1.sort()
  104. finish(selected_firmid, all_1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement