def mm_reply(msg): sender = msg['User']['RemarkName'] res = Weather.GetPosition(msg['Url'].split('=')[1]) if res == False: return u'定位获取失败...请重试!' else: try: for each in info[sender]['times']: Schedule.ClearSomeone(sender + each) info[sender]['loc'] = res['cid'] info[sender]['tz'] = eval(res['tz']) Schedule.SetDailySchedule(sender, info[sender]['times'], info[sender]['loc']) with open('info.txt', 'w') as f: f.write(str(info)) f.close() print("Successfully changed " + sender + "'s position to " + res['cid']) return u'定位已修改为:' + res['admin_area'] + res['location'] except: print("Unsuccessfully changed location!") return u'定位修改失败!'
import Schedule import Weather import Wechat import time import _thread global server_tz server_tz = eval(Weather.GetPosition('auto_ip')['tz']) print('Server timezone:' + str(server_tz)) with open('info.txt', 'r') as f: info = eval(f.read()) f.close() for name, item in info.items(): Schedule.SetDailySchedule(name, item['times'], item['loc']) Wechat.LogInWechat() _thread.start_new_thread(Wechat.run, ()) print('Wechat is running in a new thread!') while True: Schedule.RunPending() time.sleep(5) Wechat.LogoutWechat()