情景1:现在有一个道具商店,共有10个道具可购买。玩家可使用某道具或钻石刷新道具商店中的道具,或者系统会每隔2小时赠送一次刷新次数。
问题1:如何实现间隔2小时实时刷新?
from datetime import datetime def cal_count(timestamp): now_dt = datetime.now() base_dt = datetime.fromtimestamp(0) last_dt = datetime.fromtimestamp(timestamp) count = ((now_dt.date() - base_dt.date()).days*12 + now_dt.hour/2) - \ ((last_dt.date() - base_dt.date()).days*12 + last_dt.hour/2) return count if __name__ == "__main__": last_ts = 1433000132 print cal_count(last_ts)