def updata(): #while continueUpdata: url = 'http://101.132.169.177/magicmirror/genxin/sensorUpdata.php' #apiheaders = {'U-ApiKey': 'aQhiPsTqV9jHnnE7','content-type':'application/json'} smokedata = smoke.smoke() wenshidata = wenshidu.wenshi() temperature = wenshidata[0] humidity = wenshidata[1] params = urllib.parse.urlencode({ 'temperature': temperature, 'humidity': humidity, 'smoke': smokedata }) f = urllib.request.urlopen( "http://101.132.169.177/magicmirror/genxin/get_sensor.php?%s" % params) print(f.read().decode('utf-8')) #time.sleep(60) #while True: #updata()
def gexin(): while continue_reading: apiurl = 'http://101.132.169.177/magicmirror/genxin/jsonshuju.php' apiheaders = { 'U-ApiKey': 'aQhiPsTqV9jHnnE7', 'content-type': 'application/json' } username = '******' yanwu = smoke.smoke() jifen = str(wenshidu.wenshi()) payload = {'username': username, 'yanwu': smoke, 'jifen': jifen} r = requests.post(apiurl, headers=apiheaders, data=json.dumps(payload)) print(r.text) time.sleep(5)
def gexin(): while continue_reading: #在使用是apiurl要根据服务器地址修改才能使用 apiurl = 'http://101.132.169.177/magicmirror/genxin/json.php' apiheaders = {'U-ApiKey': 'aQhiPsTqV9jHnnE7','content-type':'application/json'} uid ='caonima' key= '1456' #jifen=round(ccxt.hx711read(),1) #jifen=str(jifen) jifen = str(wenshidu.wenshi()) payload={'username':uid,'key':key,'jifen':jifen} r = requests.post(apiurl, headers=apiheaders, data=json.dumps(payload)) #print (r.text[10:100]) rt=r.text[17:] rt =rt.encode('latin-1').decode('unicode-escape') return rt
def initUI(self): # 背景颜色 col = QColor("black") self.setStyleSheet("QWidget { background-color: %s }" % col.name()) textCol = QPalette() textCol.setColor(QPalette.WindowText, Qt.white) #天气模块 #标签-城市 self.city = QLabel(self) self.city.setAlignment(Qt.AlignCenter) self.city.setText('镇江') self.city.setPalette(textCol) self.city.setFont(QFont("Helvetica", 48)) self.city.move(50, 20) #标签-天气 self.wea = QLabel(self) self.wea.setAlignment(Qt.AlignCenter) weaCon = weather.weather() self.wea.setText(weaCon['type']) self.wea.setPalette(textCol) self.wea.setFont(QFont("Helvetica", 28)) self.wea.move(200, 30) #标签-最高温度 self.high = QLabel(self) self.high.setAlignment(Qt.AlignCenter) highCon = weather.weather() self.high.setText(highCon['high'] + ' ~') self.high.setPalette(textCol) self.high.setFont(QFont("Helvetica", 18)) self.high.move(50, 100) #标签-最低温度 self.low = QLabel(self) self.low.setAlignment(Qt.AlignCenter) lowCon = weather.weather() self.low.setText(lowCon['low']) self.low.setPalette(textCol) self.low.setFont(QFont("Helvetica", 18)) self.low.move(200, 100) #时间模块 #标签-时间 self.time = QLabel(self) self.time.setAlignment(Qt.AlignCenter) self.time.setText(time.strftime("%I:%M", time.localtime())) self.time.setPalette(textCol) self.time.setFont(QFont("Helvetica", 48)) self.time.move(780, 20) #标签-当天日期 self.date = QLabel(self) self.date.setAlignment(Qt.AlignCenter) dateCon = str(datetime.date.today()) self.date.setText(dateCon) self.date.setPalette(textCol) self.date.setFont(QFont("Helvetica", 18)) self.date.move(825, 100) #标签-星期数 self.week = QLabel(self) self.week.setAlignment(Qt.AlignCenter) dayOfWeek = str(time.strftime("%A", time.localtime())) self.week.setText(dayOfWeek) self.week.setPalette(textCol) self.week.setFont(QFont("Helvetica", 16)) self.week.move(900, 140) #备忘录模块 #标签Title-Memo self.memo = QLabel(self) self.memo.setText('备忘录') self.memo.setPalette(textCol) self.memo.setFont(QFont("Helvetica", 28)) self.memo.move(50, 220) #memodata data_memo = memo.memo() #memo-content self.memoCont = QLabel(self) self.memoCont.setText(data_memo[2]) self.memoCont.setPalette(textCol) self.memoCont.setFont(QFont("Helvetica", 18)) self.memoCont.move(50, 300) #课程表模块 #标签Title-Schedule self.sch_tt = QLabel(self) self.sch_tt.setText('课程表') self.sch_tt.setPalette(textCol) self.sch_tt.setFont(QFont("Helvetica", 28)) self.sch_tt.move(820, 220) #scheduledata data_sch = schedule.schedule() #schedule-first第一节 self.sch1 = QLabel(self) self.sch1.setText('第一节: ' + data_sch[0]) self.sch1.setPalette(textCol) self.sch1.setFont(QFont("Helvetica", 18)) self.sch1.move(720, 300) #schedule-second self.sch2 = QLabel(self) self.sch2.setText('第二节: ' + data_sch[1]) self.sch2.setPalette(textCol) self.sch2.setFont(QFont("Helvetica", 18)) self.sch2.move(720, 340) #schedule-third self.sch3 = QLabel(self) self.sch3.setText('第三节: ' + data_sch[2]) self.sch3.setPalette(textCol) self.sch3.setFont(QFont("Helvetica", 18)) self.sch3.move(720, 380) #schedule-fourth self.sch4 = QLabel(self) str4 = data_sch[3] self.sch4.setText('第四节: ' + data_sch[3]) self.sch4.setPalette(textCol) self.sch4.setFont(QFont("Helvetica", 18)) self.sch4.move(720, 420) #schedule-fifth self.sch5 = QLabel(self) str5 = data_sch[4] self.sch5.setText('第五节: ' + data_sch[4]) self.sch5.setPalette(textCol) self.sch5.setFont(QFont("Helvetica", 18)) self.sch5.move(720, 460) #新闻模块 #标签Title-NEWS self.news_tt = QLabel(self) self.news_tt.setText('News') self.news_tt.setPalette(textCol) self.news_tt.setFont(QFont("Helvetica", 28)) self.news_tt.move(50, 600) #标签-新闻爬虫 self.newsCont = QLabel(self) new = news.new() self.newsCont.setText(new) self.newsCont.setPalette(textCol) self.newsCont.setFont(QFont("Helvetica", 18)) self.newsCont.setGeometry(50, 650, 900, 30) self.newsCont.move(50, 650) #传感器模块 #标签-温度 self.wen = QLabel(self) self.wen.setAlignment(Qt.AlignCenter) wenCon = wenshidu.wenshi() self.wen.setText('温度:' + str(wenCon[0]) + '℃') self.wen.setPalette(textCol) self.wen.setFont(QFont("Helvetica", 18)) self.wen.move(50, 710) #标签-湿度 self.shi = QLabel(self) self.shi.setAlignment(Qt.AlignCenter) shiCon = wenshidu.wenshi() self.shi.setText('湿度:' + str(shiCon[1]) + '%') self.shi.setPalette(textCol) self.shi.setFont(QFont("Helvetica", 18)) self.shi.move(860, 710) #标签-烟雾 self.smoke = QLabel(self) yan = smoke.smoke() self.smoke.setText('烟雾:' + yan) self.smoke.setPalette(textCol) self.smoke.setFont(QFont("Helvetica", 18)) self.smoke.move(460, 710) #新建一个QTimer对象 self.timer = QTimer() self.timer.setInterval(1000) self.timer.start() # 信号连接到槽 self.timer.timeout.connect(self.onTimerOut) #绝对定位 self.setGeometry(0, 0, 1024, 768) self.setWindowTitle('绝对定位') self.show()
def run(self): while True: text_wenshi = wenshidu.wenshi() self.update_date.emit(str(text_wenshi)) time.sleep(1)
def initUI(self): # 背景颜色 col = QColor("black") self.setStyleSheet("QWidget { background-color: %s }" % col.name()) textCol = QPalette() textCol.setColor(QPalette.WindowText, Qt.white) #标签-时间 self.label1 = QLabel(self) self.label1.setAlignment(Qt.AlignCenter) self.label1.setText(time.strftime("%I:%M", time.localtime())) self.label1.setPalette(textCol) self.label1.setFont(QFont("Helvetica", 48)) self.label1.move(780, 20) #标签-温度 self.label3 = QLabel(self) self.label3.setAlignment(Qt.AlignCenter) text = wenshidu.wenshi() te = str(text[0]) self.label3.setText('温度:' + te + '℃') self.label3.setPalette(textCol) self.label3.setFont(QFont("Helvetica", 18)) self.label3.move(50, 710) #标签-湿度 self.label4 = QLabel(self) self.label4.setAlignment(Qt.AlignCenter) text = wenshidu.wenshi() te = str(text[1]) self.label4.setText('湿度:' + te + '%') self.label4.setPalette(textCol) self.label4.setFont(QFont("Helvetica", 18)) self.label4.move(860, 710) #标签-城市 self.label6 = QLabel(self) self.label6.setAlignment(Qt.AlignCenter) self.label6.setText('镇江') self.label6.setPalette(textCol) self.label6.setFont(QFont("Helvetica", 48)) self.label6.move(50, 20) #标签-天气 self.label7 = QLabel(self) self.label7.setAlignment(Qt.AlignCenter) text7 = weather.weather() self.label7.setText(text7['type']) self.label7.setPalette(textCol) self.label7.setFont(QFont("Helvetica", 28)) self.label7.move(200, 30) #标签-最高温度 self.label8 = QLabel(self) self.label8.setAlignment(Qt.AlignCenter) text8 = weather.weather() self.label8.setText(text8['high'] + ' ~') self.label8.setPalette(textCol) self.label8.setFont(QFont("Helvetica", 18)) self.label8.move(50, 100) #标签-最低温度 self.label9 = QLabel(self) self.label9.setAlignment(Qt.AlignCenter) text9 = weather.weather() self.label9.setText(text9['low']) self.label9.setPalette(textCol) self.label9.setFont(QFont("Helvetica", 18)) self.label9.move(200, 100) #标签-当天日期 self.label10 = QLabel(self) self.label10.setAlignment(Qt.AlignCenter) text10 = str(datetime.date.today()) self.label10.setText(text10) self.label10.setPalette(textCol) self.label10.setFont(QFont("Helvetica", 18)) self.label10.move(825, 100) #标签-星期数 self.label11 = QLabel(self) self.label11.setAlignment(Qt.AlignCenter) dayOfWeek = str(time.strftime("%A", time.localtime())) self.label11.setText(dayOfWeek) self.label11.setPalette(textCol) self.label11.setFont(QFont("Helvetica", 16)) self.label11.move(900, 140) #标签Title-NEWS self.news_tt = QLabel(self) self.news_tt.setText('News') self.news_tt.setPalette(textCol) self.news_tt.setFont(QFont("Helvetica", 28)) self.news_tt.move(50, 600) #标签-新闻爬虫 self.newsCont = QLabel(self) new = "新闻爬虫_新闻爬虫_新闻爬虫_新闻爬虫_新闻爬虫_新闻爬虫_新闻爬虫_新闻爬虫_" self.newsCont.setText(new) self.newsCont.setPalette(textCol) self.newsCont.setFont(QFont("Helvetica", 18)) self.newsCont.setGeometry(50, 650, 900, 30) self.newsCont.move(50, 650) #标签-Event #标签Title-Event self.memo = QLabel(self) self.memo.setText('备忘录') self.memo.setPalette(textCol) self.memo.setFont(QFont("Helvetica", 28)) self.memo.move(50, 220) #memodata data_memo = ["title", "备忘录", "备忘录__备忘录__备忘录__备忘录__备忘录__备忘录__"] #memo-content self.memoCont = QLabel(self) self.memoCont.setText(data_memo[1] + ":" + data_memo[2]) self.memoCont.setPalette(textCol) self.memoCont.setFont(QFont("Helvetica", 18)) self.memoCont.move(50, 300) #标签-烟雾 self.label15 = QLabel(self) #yan=smoke.smoke() yan = "dangerous" self.label15.setText('烟雾:' + yan) self.label15.setPalette(textCol) self.label15.setFont(QFont("Helvetica", 18)) self.label15.move(460, 710) #标签Title-Schedule self.sch_tt = QLabel(self) self.sch_tt.setText('课程表') self.sch_tt.setPalette(textCol) self.sch_tt.setFont(QFont("Helvetica", 28)) self.sch_tt.move(820, 220) #scheduledata data_sch = schedule.schedule() #schedule-first第一节 self.sch1 = QLabel(self) self.sch1.setText('第一节: ' + data_sch[0]) self.sch1.setPalette(textCol) self.sch1.setFont(QFont("Helvetica", 18)) self.sch1.move(720, 300) #schedule-second self.sch2 = QLabel(self) self.sch2.setText('第二节: ' + data_sch[1]) self.sch2.setPalette(textCol) self.sch2.setFont(QFont("Helvetica", 18)) self.sch2.move(720, 340) #schedule-third self.sch3 = QLabel(self) self.sch3.setText('第三节: ' + data_sch[2]) self.sch3.setPalette(textCol) self.sch3.setFont(QFont("Helvetica", 18)) self.sch3.move(720, 380) #schedule-fourth self.sch4 = QLabel(self) self.sch4.setText('第四节: ' + data_sch[3]) self.sch4.setPalette(textCol) self.sch4.setFont(QFont("Helvetica", 18)) self.sch4.move(720, 420) #schedule-fifth self.sch5 = QLabel(self) self.sch5.setText('第五节: ' + data_sch[4]) self.sch5.setPalette(textCol) self.sch5.setFont(QFont("Helvetica", 18)) self.sch5.move(720, 460) #新建一个QTimer对象 self.timer = QTimer() self.timer.setInterval(1000) self.timer.start() # 信号连接到槽 self.timer.timeout.connect(self.onTimerOut) #绝对定位 self.setGeometry(0, 0, 1024, 768) self.setWindowTitle('绝对定位') self.show()
def run(self): while True: text_wenshi = wenshidu.wenshi() print(text_wenshi) self.update_date.emit(text_wenshi) # 发射信号 time.sleep(1)