2
# -*- coding: utf-8 -*-
5
# Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd
8
# This program is free software: you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License version 3, as published
10
# by the Free Software Foundation.
12
# This program is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranties of
14
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
# PURPOSE. See the GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License along
18
# with this program. If not, see <http://www.gnu.org/licenses/>.
25
sys.setdefaultencoding("utf-8")
26
#from xdg import BaseDirectory as xdg
28
#CREATE_AREA = "create table area (id varchar(32) primary key, province varchar(64), \
29
# city varchar(64), county varchar(64), pinyin varchar(64))"
30
#INSERT_AREA = "insert into area (id, province, city, county, pinyin) \
31
# values('%s', '%s', '%s', '%s', '%s')"
32
#QUERY_AREA = "select * from area where id='%s'"
33
QUERY_COUNTY = "select county from area where province='%s' and city='%s'"
34
QUERY_ID = "select id from area where province='%s' and city='%s' and county='%s'"
35
#RESET_AREA = "delete from area"
36
#UPDATE_AREA = "update area set pinyin='%s' where id='%s'"
40
#CREATE_CITY = "create table city (province varchar(64), cityname varchar(64))"
41
#INSERT_CITY = "insert into city (province, cityname) \
43
QUERY_CITY_LIST = "select cityname from city where province='%s'"
46
#WEATHER_CACHE_DIR = os.path.join(xdg.xdg_cache_home, "indicator-china-weather")
47
#CHN_CITY_LIST_FILE = os.path.join(os.path.abspath(os.path.curdir), "locations.txt")
48
#CITY_LIST_FILE = os.path.join(os.path.abspath(os.path.curdir), "city.txt")
50
#DB_PATH = os.path.join(os.path.abspath(os.path.curdir), "weather-app.db")
92
destFile = os.path.join('/var/lib/youker-assistant-daemon',"weather-app.db")
93
if not os.path.exists(destFile):
94
print "error with db file"
97
self.connect = sqlite3.connect(destFile, check_same_thread=False)
99
# self.connect = sqlite3.connect(DB_PATH, check_same_thread=False)
100
self.cursor = self.connect.cursor()
107
# def create_area_table(self):
108
# self.cursor.execute(CREATE_AREA)
111
# def reset_area_table(self):
112
# self.cursor.execute(RESET_AREA)
113
# self.connect.commit()
115
# def search_record(self, id):
116
# self.cursor.execute(QUERY_AREA % (id))
117
# res = self.cursor.fetchall()
122
def get_province_list(self):
125
def search_counties(self, province, city):
126
self.cursor.execute(QUERY_COUNTY % (province, city))
127
res = self.cursor.fetchall()
133
def search_id(self, province, city, county):
134
self.cursor.execute(QUERY_ID % (province, city, county))
135
res = self.cursor.fetchall()
142
# def insert_area_data(self):
143
# file = open(CHN_CITY_LIST_FILE, 'r')
144
# for line in file.readlines():
145
# if line not in (False, None, '') and ',' in line and ':' in line:
146
# line_list = line.strip('\n').split(':')
147
# city_list = line_list[0].split(',')
148
# self.cursor.execute(INSERT_AREA % (line_list[1],city_list[0],city_list[1],city_list[2],line_list[2]))
149
# self.connect.commit()
156
# def create_city_table(self):
157
# self.cursor.execute(CREATE_CITY)
160
# def insert_city_data(self):
161
# file = open(CITY_LIST_FILE, 'r')
162
# for line in file.readlines():
163
# if line not in (False, None, '') and ',' in line:
164
# line_list = line.strip('\n').split(',')
165
# self.cursor.execute(INSERT_CITY % (line_list[0],line_list[1]))
166
# self.connect.commit()
169
def search_city_table(self, province):
170
self.cursor.execute(QUERY_CITY_LIST % (province))
171
res = self.cursor.fetchall()
177
if __name__ == "__main__":
179
# db.create_area_table()
180
#db.insert_area_data()
182
# db.create_city_table()
183
# db.insert_city_data()