test.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. 测试代码
  3. """
  4. import numpy as np
  5. from pandas import DataFrame
  6. from feishu.feishu import Feishu
  7. from applications.mysql import Mysql
  8. F = Feishu()
  9. M = Mysql()
  10. sql = "SELECT * FROM we_analysis_results where mini_program = '票圈视频+' and date = \'2024-01-15\';"
  11. if __name__ == '__main__':
  12. data_lines = M.select(sql)
  13. L = []
  14. title_list = []
  15. for line in data_lines:
  16. result = [i for i in ([line[3]] + list(line[5:]))]
  17. L.append(result)
  18. w = transposed_matrix = np.transpose(L)
  19. first_row = w[0, :]
  20. w = w[1:, :]
  21. non_zero_rows = np.any(w != 0, axis=1)
  22. w_filtered = w[non_zero_rows]
  23. my_list = w_filtered.tolist()
  24. rows = len(my_list)
  25. datas = [["2024-01-15", "票圈视频+", "", "ab{}".format(i)] + my_list[i] for i in range(rows)]
  26. F.insert_value(
  27. sheet_id="gwzBOM",
  28. values=datas,
  29. ranges="A2:AH22"
  30. )
  31. # # 插入日期
  32. # F.insert_value(
  33. # sheet_id="gwzBOM",
  34. # values=[["2024-01-15", "票圈视频+"] for i in range(rows)],
  35. # ranges="A2:B22"
  36. # )
  37. # titles = [0] + list(first_row)
  38. # print(titles)
  39. # DF = DataFrame(w_with_labels, columns=titles)
  40. # DF.to_excel("test.xlsx", index=False)