idl_tv_avg_ratings_stat.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. #coding=utf-8
  3. """计算每个电视剧的收视率
  4. """
  5. import datetime
  6. import sys
  7. from fty_util.common import Mysql
  8. class tv_avg_ratings_stat():
  9. def province(self):
  10. conn = Mysql.createOfflineConn()
  11. sql = """
  12. truncate table idl.tv_avg_ratings
  13. """
  14. Mysql.execute(sql, conn=conn)
  15. sql = """
  16. insert into idl.tv_avg_ratings (channel, theater_attribute, tv_name, tv_id, tv_date, value)
  17. select channel, theater_attribute, tv_name, tv_id, tv_date, value from tmp.tv_avg_ratings
  18. """
  19. Mysql.execute(sql, conn=conn)
  20. Mysql.close(conn)
  21. def area(self):
  22. conn = Mysql.createOfflineConn()
  23. sql = """
  24. truncate table idl.area_tv_avg_ratings
  25. """
  26. Mysql.execute(sql, conn=conn)
  27. sql = """
  28. insert into idl.area_tv_avg_ratings (channel, theater_attribute, tv_name, tv_id, tv_date, value)
  29. select channel, theater_attribute, tv_name, tv_id, tv_date, value from tmp.area_tv_avg_ratings
  30. """
  31. Mysql.execute(sql, conn=conn)
  32. Mysql.close(conn)
  33. if __name__ == '__main__':
  34. if len(sys.argv) != 2:
  35. print '没有输入参数,退出'
  36. sys.exit(0)
  37. print 'method name is ' + sys.argv[1]
  38. obj = tv_avg_ratings_stat()
  39. try:
  40. getattr(obj, sys.argv[1])()
  41. except Exception, e:
  42. print e