idl_tv_category_stat.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python
  2. #coding=utf-8
  3. """近一年电视台平均收视率
  4. """
  5. import sys
  6. from fty_util.common import Mysql, Util
  7. reload(sys)
  8. sys.setdefaultencoding('utf8')
  9. class tv_category_stat():
  10. def province(self):
  11. conn = Mysql.createOfflineConn()
  12. sql = """
  13. truncate table idl.tv_category_stat
  14. """
  15. Mysql.execute(sql, conn=conn)
  16. # 将数据从tmp库插到idl库
  17. sql = """
  18. insert into idl.tv_category_stat (tv_id, category, channel, theater_attribute)
  19. select tv_id, category, channel, theater_attribute from tmp.tv_category_stat
  20. """
  21. Mysql.execute(sql, conn=conn)
  22. Mysql.close(conn)
  23. def area(self):
  24. conn = Mysql.createOfflineConn()
  25. sql = """
  26. truncate table idl.area_tv_category_stat
  27. """
  28. Mysql.execute(sql, conn=conn)
  29. # 将数据从tmp库插到idl库
  30. sql = """
  31. insert into idl.area_tv_category_stat (tv_id, category, channel, theater_attribute)
  32. select tv_id, category, channel, theater_attribute from tmp.area_tv_category_stat
  33. """
  34. Mysql.execute(sql, conn=conn)
  35. Mysql.close(conn)
  36. if __name__ == '__main__':
  37. if len(sys.argv) != 2:
  38. print '没有输入参数,退出'
  39. sys.exit(0)
  40. print 'method name is ' + sys.argv[1]
  41. obj = tv_category_stat()
  42. try:
  43. getattr(obj, sys.argv[1])()
  44. except Exception, e:
  45. print e