资源简介
定时拉取指定城市天气并发送给指定好友,资源讲解地址:https://www.cnblogs.com/swarmbees/p/10023491.html
代码片段和文件信息
# coding: utf-8
import os
class City(object):
def __init__(self):
self.city = {}
def load(self file):
if os.path.exists(file):
with open(file ‘r‘ encoding = ‘utf-8‘) as f:
cityInfo = f.readline().strip(‘\n‘)
while cityInfo:
datas = cityInfo.split(‘:‘)
self.city[datas[0]] = datas[1]
cityInfo = f.readline().strip(‘\n‘)
def find_code(self city_name):
if city_name in self.city:
return self.city[city_name]
return ‘‘
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
I.A.... 2026 2018-11-26 23:09 weath_report.py
I.A.... 602 2018-11-26 20:45 city_code.py
I.A.... 8268 2018-11-26 20:45 city_code.txt
I.A.... 581 2018-11-26 22:52 mybot.py
I.A.... 1680 2018-11-26 21:31 sender.py
I.A.... 1466 2018-11-26 20:45 Timer.py
I.A.... 1825 2018-11-26 20:45 weath_info.py
----------- --------- ---------- ----- ----
16448 7
评论
共有 条评论