def calculate_R_value(self, T_inside_wall, T_inside_reflected): T_inside_wall_C = self.pixel_to_temperature(T_inside_wall) T_inside_reflected_C = self.pixel_to_temperature(T_inside_reflected) self.T_inside_wall = ptemp.c2k(T_inside_wall_C) self.T_inside_reflected = ptemp.c2k(T_inside_reflected_C) self.R = abs(self.T_inside_air - self.T_outside_air) / \ (self.alpha * abs(self.T_inside_air - self.T_inside_wall) + self.epsilon * self.sigma * abs(self.T_inside_wall ** 4 - self.T_inside_reflected ** 4)) return self.R
def calculate_R_value_list(self, T_inside_walls, T_inside_reflected): T_inside_reflected = ptemp.c2k(T_inside_reflected) for T_inside_wall in T_inside_walls: T_inside_wall_C = self.pixel_to_temperature(T_inside_wall) print("The inside wall temps is ", T_inside_wall_C) # T_inside_reflected_C = self.pixel_to_temperature(T_inside_reflected) T_inside_wall_K = ptemp.c2k(T_inside_wall_C) R = abs(self.T_inside_air - self.T_outside_air) / \ (self.alpha * abs(self.T_inside_air - T_inside_wall_K) + self.epsilon * self.sigma * abs(T_inside_wall_K ** 4 - T_inside_reflected ** 4)) self.R_values.append(R) return self.R_values
def __init__(self, T_inside_air, T_outside_air, air_velocity=1.0, epsilon=0.99): # air_velocity should be in meters / second # alpha is the convective heat transfer coefficient # epsilon is the thermal emissivity # sigma is the Stefan-Boltzmann constant self.alpha = 3.81 * air_velocity self.epsilon = epsilon self.sigma = 5.67e-8 # W.(m^-2).(K^-4) self.T_inside_air = ptemp.c2k(T_inside_air) # K self.T_outside_air = ptemp.c2k(T_outside_air) # K self.R_values = []
def convertTemperature(input_numerical_value, input_uom, target_uom): outputTemp = 0.0 if(input_uom == 'Kelvin'): if(target_uom == 'Celsius'): outputTemp = pytemperature.k2c(float(input_numerical_value)) elif(target_uom == 'Fahrenheit'): outputTemp = pytemperature.k2f(float(input_numerical_value)) if(input_uom == 'Celsius'): if(target_uom == 'Kelvin'): outputTemp = pytemperature.c2k(float(input_numerical_value)) elif(target_uom == 'Fahrenheit'): outputTemp = pytemperature.c2f(float(input_numerical_value)) if(input_uom == 'Fahrenheit'): if(target_uom == 'Kelvin'): outputTemp = pytemperature.c2k(float(input_numerical_value)) elif(target_uom == 'Celsius'): outputTemp = pytemperature.c2f(float(input_numerical_value)) return outputTemp
def computeAirDensity(self, temp, partialPressureDryPascal, relativeHumidity): """ computes the current air density """ # auxiliary variables RT = self.IDEAL_GAS * pytemperature.c2k(temp) partialPressureWaterVapor = self.computePartialPressureWaterVapor( temp, relativeHumidity) partialDensityDry = partialPressureDryPascal * self.MODULAR_MASS_DRY / RT partialDensityWaterVapor = partialPressureWaterVapor * self.MODULAR_MASS_WATER_VAPOR / RT airDensity = partialDensityDry + partialDensityWaterVapor return airDensity
def sensor_config(): print("sensor config") client = InfluxDBClient(host, port, user, password, dbname) rs = client.query( 'SELECT mean(*) FROM "home"."autogen"."data" WHERE time > now() - 60s AND "node"!="server"' ) rs = list(rs.get_points()) temp_k = pytemperature.c2k(rs[0]['mean_temperature']) print(temp_k) rel_H = rs[0]['mean_humidity'] pressure = rs[0]['mean_pressure']
def search(request): if 't' in request.GET: api_url = 'http://127.0.0.1:8000/temperatures/' res = requests.get(api_url) data = res.json() #получаем список дат for c in data: if request.GET['t'] in c['date']: if 'g' in request.GET: if request.GET['g'] == 'f': return HttpResponse(pytemperature.c2f( c['temperature'])) #Фаренгейты elif request.GET['g'] == 'k': return HttpResponse(pytemperature.c2k( c['temperature'])) #Кельвины return HttpResponse(c['temperature']) return HttpResponse('empty request')
def status(config={}, output="default"): result = {} if output == "signalk": logger.debug("prepping sk output...") from pivac import sk_init_deltas, sk_add_source, sk_add_value deltas = sk_init_deltas() cams = config["inputs"] for cam, camdict in cams.iteritems(): logger.debug("iterating camera %s", cam) if output == "signalk": sk_source = sk_add_source(deltas, "flirfx:%s" % cam) try: # no session yet if "fake" in camdict and camdict["fake"] == True: temp_units = "F" temp_value = 68 humidity_value = 49 else: if cam not in Cams: logger.debug("logging into camera...") Cams[cam] = {} r = requests.post( 'http://%s/API/1.0/ChiconyCameraLogin' % cam, data='{ "password" : "%s" }' % camdict["pwd"]) session = r.cookies['Session'] Cams[cam]["cookies"] = dict(Session=session) req = requests.post( 'http://%s/API/1.1/CameraStatus' % cam, cookies=cookies, data='{ "getCameraStatus" : [ "humidity", "temperature"] }' ) res = req.json() temp_units = res['temperature']['tempUnits'] temp_value = res['temperature']['tempValue'] humidity_value = res['humidity']['humidityLevel'] if temp_units == 'F': temp_value = pytemperature.f2k(temp_value) elif temp_units == 'C': temp_value = pytemperature.c2k(temp_value) if output == "signalk": sk_add_value(sk_source, "%s.temperature" % camdict["sk_path"], temp_value) sk_add_value(sk_source, "%s.humidity" % camdict["sk_path"], humidity_value) else: if camdict["scale"] == "fahrenheit": temp_value = pytemperature.k2f(temp_value) if camdict["scale"] == "celcius": temp_value = pytemperature.k2c(temp_value) result[cam] = {} result[cam]["temperature"] = temp_value result[cam]["humidity"] = humidity_value except: logger.exception("error getting data from FLIR camera %s" % cam) if output == "signalk": return deltas else: return result
def virtualAssistant(): SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'] MONTHS = [ "january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december" ] DAYS = [ "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" ] DAY_EXTENTIONS = ["rd", "th", "st", "nd"] # def credAccess(): # with open("userCred.txt", 'rt') as fin: # creds = fin.readlines() # username = creds[1] # USERNAME = username[0:len(username) - 1] # email_id = creds[3] # USER_EMAIL_ID = email_id[0:len(email_id) - 1] # password = creds[5] # USER_EMAIL_PASS = password[0:len(password) - 1] # sql = creds[7] # USER_SQL_PASS = sql[0:len(sql) - 1] # return USERNAME, USER_EMAIL_ID, USER_EMAIL_PASS, USER_SQL_PASS def speak(text): engine = pyttsx3.init("sapi5") # object creation """ RATE""" rate = engine.getProperty( 'rate') # getting details of current speaking rate engine.setProperty('rate', 122) # setting up new voice rate """VOLUME""" volume = engine.getProperty( 'volume') # getting to know current volume level (min=0 and max=1) engine.setProperty('volume', 1.0) # setting up volume level between 0 and 1 """VOICE""" voices = engine.getProperty( 'voices') # getting details of current voice # engine.setProperty('voice', voices[0].id) #changing index, changes voices. o for male engine.setProperty( 'voice', voices[1].id) # changing index, changes voices. 1 for female engine.say(text) engine.runAndWait() try: recognitionMode = int( input('''By which mode would you like to give commands : 1 - Voice Mode 2 - Script Mode \n''')) except: print("sorry you entered wrong value") def take_command(): global query if recognitionMode == 1: # It takes microphone input from the user and returns string output r = sr.Recognizer() with sr.Microphone() as source: print("Listening...") r.pause_threshold = 1 audio = r.listen(source) try: print("Recognizing...") query = r.recognize_google(audio, language='en-in') print(f"User said: {query}\n") except Exception: print("Say that again please...") return "None" elif recognitionMode == 2: try: query = input('Enter your Command : ') except Exception as error: print(error) return query.lower() def send_sms(number, message): url = 'https://www.fast2sms.com/dev/bulk' params = { 'authorization': 'R4UilqdkJNw1PKHu2j3fb0QsgEx7pWMYO9BItXnGvc5Cr8zoDAj2bBqMs4n9lLuNXaW85wEPhYJdUiQo', 'sender_id': 'FSTSMS', 'message': str(input("Type a message : ")), 'language': 'english', 'route': 'p', 'numbers': number } response = requests.get(url, params=params) dic = response.json() print(dic) # def authenticate_google(): # """Shows basic usage of the Google Calendar API.Prints the start and name of the next 10 events on the user's calendar.""" # credits = None # if os.path.exists('token.pickle'): # with open('token.pickle', 'rb') as token: # credits = pickle.load(token) # if not credits or not credits.valid: # if credits and credits.expired and credits.refresh_token: # credits.refresh(Request()) # else: # flow = InstalledAppFlow.from_client_secrets_file( # 'credentials.json', SCOPES) # credits = flow.run_local_server(port=0) # with open('token.pickle', 'wb') as token: # pickle.dump(credits, token) # service = build('calendar', 'v3', credentials=credits) # return service def get_events(day, service): # Call the Calendar API date = datetime.datetime.combine(day, datetime.datetime.min.time()) end_date = datetime.datetime.combine(day, datetime.datetime.max.time()) utc = pytz.UTC date = date.astimezone(utc) end_date = end_date.astimezone(utc) events_result = service.events().list(calendarId='primary', timeMin=date.isoformat(), timeMax=end_date.isoformat(), singleEvents=True, orderBy='startTime').execute() events = events_result.get('items', []) if not events: speak('No upcoming events found.') else: speak(f"You have {len(events)} events on this day.") for event in events: start = event['start'].get('dateTime', event['start'].get('date')) print(start, event['summary']) start_time = str(start.split("T")[1].split("-")[0]) if int(start_time.split(":")[0]) < 12: start_time = start_time + "am" else: start_time = str(int(start_time.split(":")[0]) - 12) + start_time.split(":")[1] start_time = start_time + "pm" speak(event["summary"] + " at " + start_time) def get_date(text): text = text.lower() today = datetime.date.today() if text.count("today") > 0: return today day = -1 day_of_week = -1 month = -1 year = today.year for word in text.split(): if word in MONTHS: month = MONTHS.index(word) + 1 elif word in DAYS: day_of_week = DAYS.index(word) elif word.isdigit(): day = int(word) else: for ext in DAY_EXTENTIONS: found = word.find(ext) if found > 0: try: day = int(word[:found]) except: pass # THE NEW PART STARTS HERE if month < today.month and month != -1: # if the month mentioned is before the current month set the year to the next year = year + 1 # This is slightly different from the video but the correct version if month == -1 and day != -1: # if we didn't find a month, but we have a day if day < today.day: month = today.month + 1 else: month = today.month # if we only found a dta of the week if month == -1 and day == -1 and day_of_week != -1: current_day_of_week = today.weekday() dif = day_of_week - current_day_of_week if dif < 0: dif += 7 if text.count("next") >= 1: dif += 7 return today + datetime.timedelta(dif) if day != -1: # FIXED FROM VIDEO return datetime.date(month=month, day=day, year=year) def sendEmail(to, content): server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.login('*****@*****.**', 'you know that') subject = "Contact book data" server.sendmail('*****@*****.**', to, content, subject) server.close() def note(text): date = datetime.datetime.now() file_name = str(date).replace(":", "-") + "-note.txt" with open(file_name, "w") as f: f.write(text) osCommandString = f"notepad.exe {file_name}" os.system(osCommandString) def TimeConversion(seconds): minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) return f"{hours:d}:{minutes:02d}:{seconds:02d}" def greet(name): hour = int(datetime.datetime.now().hour) if 0 <= hour < 12: speak("Good Morning!" + str(name)) elif 12 <= hour < 16: speak("Good Afternoon!" + str(name)) else: speak("Good Evening!" + str(name)) def history(text): date_time = datetime.datetime.now().strftime("%d/%m/%Y, %H:%M:%S") f = open("Hello.txt", "a") f.write(f"{date_time} : {text}\n\n") def contactBook(USER_SQL_PASS): global emailID mydb = MySQLConnection(host="localhost", user="******", password=USER_SQL_PASS, database="contact_book") mycursor = mydb.cursor() name1 = str(input("Enter the name : ")) mycursor.execute("SELECT * FROM contact_table") myresult = mycursor.fetchall() for x in myresult: if name1 == x[0]: emailID = x[1] break else: print("Record not found") insertChoice = input("Would you like to add contact ? ") if insertChoice.lower().startswith("y"): mydb1 = MySQLConnection(host="localhost", user="******", password="******", database="contact_book") mycursor1 = mydb1.cursor() mail = str(input("Enter the e-mail ID of the new contact : ")) sql = "INSERT INTO contact_table(name, email_id) VALUES(%s,%s)" val = (name1, mail) mycursor1.execute(sql, val) mydb1.commit() print(mycursor1.rowcount, "record inserted.") mydb = MySQLConnection(host="localhost", user="******", password=USER_SQL_PASS, database="contact_book") mycursor = mydb.cursor() mycursor.execute("SELECT * FROM contact_table") myresult = mycursor.fetchall() for x in myresult: if name1 == x[0]: emailID = x[1] break return emailID if __name__ == "__main__": # USERNAME, USER_EMAIL_ID, USER_EMAIL_PASS, USER_SQL_PASS = credAccess() # print(USERNAME, USER_EMAIL_ID, USER_EMAIL_PASS, USER_SQL_PASS) name = getpass.getuser() greet(name) initTime = datetime.datetime.now() WAKE = "rushi" assname = WAKE # SERVICE = authenticate_google() print("Starting....") speak("I am ready") while True: text = take_command() if text.count(WAKE) > 0: text = text.replace(WAKE, "") history(text) CALENDAR_STRS = [ "what do i have", "do i have plans", "am i busy" ] for phrase in CALENDAR_STRS: if phrase in text: date = get_date(text) if date: get_events(date, SERVICE) else: speak("I don't understand") NOTE_STRS = ["make a note", "write this down", "remember this"] for phrase in NOTE_STRS: if phrase in text: speak("What would you like me to write down?") note_text = take_command() note(note_text) speak("I've made a note of that.") if 'wikipedia' in text: try: speak('Searching Wikipedia...') text = text.replace("wikipedia", "") results = wikipedia.summary(text, sentences=1) speak("According to Wikipedia") print(results) speak(results) except Exception as e: print(e) elif 'open youtube' in text: speak("Here you go to Youtube") webbrowser.open_new("https://www.youtube.com/") elif 'open classroom' in text: text = str(input("Enter the name of the class: ")) if text == "python": speak("Here is your python class") webbrowser.open_new( "https://classroom.google.com/u/3/c/MTUyNjI2NjQ4MDg5" ) elif text == "software engineering": speak("Here is your software engineering class") webbrowser.open_new( "https://classroom.google.com/u/3/c/MTUzNzQ2MDU5NDE2" ) elif text == "computer network": speak("Here is your computer network class") webbrowser.open_new( "https://classroom.google.com/u/3/c/MTE3NTUzMTY2NTMy" ) elif 'open stackoverflow' in text: speak("Here you go to Stack Over flow, Happy coding") webbrowser.open_new("https://www.stackoverflow.com/") elif 'open calculator' in text or 'open calc' in text: os.system("calc.exe") elif 'time' in text: strTime = datetime.datetime.now().strftime("%H:%M:%S") speak(f"The time is {strTime}") elif 'email' in text: try: speak("What should I say?") content = take_command() speak("whom should i send") try: to = contactBook(USER_SQL_PASS) sendEmail(to, content) speak("Your Email has been sent !") except: to = take_command() sendEmail(to, content) speak("Your Email has been sent !") except Exception as e: print(e) speak("I am not able to send this email") elif 'open notepad' in text or 'notepad' in text: os.system("Notepad.exe") elif 'clear screen' in text: os.system('cls') elif 'how are you' in text: speak("I am fine, Thank you") speak("How are you") text = take_command() if 'i am fine' in text or "good" in text: speak("It's good to know that your fine") elif "change name" in text: speak("What would you like to call me, Sir ") WAKE = take_command() speak("Thanks for naming me") elif "what's your name" in text or "what is your name" in text: speak("My friends call me") speak(assname) print("My friends call me", assname) elif "who made you" in text or "who created you" in text: speak("I have been created by Rushi.") elif 'favourite song' in text: speak( "I don\'t have any favourite song but my creators have a common favourite song So, you can consider it as my favourite song also" ) try: os.system("start udd_gaye.mpeg") except: webbrowser.open( "https://play.google.com/music/listen?u=0#/sr/udd gaye" ) elif "flip a coin" in text: num = random.randint(0, 1) print("Flipping your coin...") if num == 1: print("Heads: Front Face\n") else: print("Tails: Back Face\n") elif 'joke' in text: joke = pyjokes.get_joke() print(joke) speak(joke) elif 'details of number' in text: a = input("Enter a number:") ch_number = phonenumbers.parse(a, "CH") print(geocoder.description_for_number(ch_number, "de")) ro_number = phonenumbers.parse(a, "RO") print(carrier.name_for_number(ro_number, "en")) elif 'call' in text: account_sid = 'ACeb2360f987b7b0b866805e4cd073cded' auth_token = 'ee459d2f4d92b10da2c6ecb9572a25da' client = Client(account_sid, auth_token) call = client.calls.create( url='http://demo.twilio.com/docs/voice.xml', to=int(input("Enter a number : ")), from_=int(input("Enter a number: "))) print(call.sid) elif 'imposter' in text: try: BODY_COLOR = 'red' BODY_SHADOW = '' GLASS_COLOR = 'skyblue' GLASS_SHADOW = '' s = turtle.getscreen() t = turtle.Turtle() def body(): t.pensize(20) t.speed(10) t.fillcolor(BODY_COLOR) t.begin_fill() # starting part t.right(90) t.forward(50) t.right(180) t.circle(40, -180) t.right(180) t.forward(200) # head part t.right(180) t.circle(100, -180) # left hand side part t.backward(20) t.left(15) t.circle(500, -20) t.backward(20) t.circle(40, -180) t.left(7) t.backward(50) # hip t.up() t.left(90) t.forward(10) t.right(90) t.down() t.right(240) t.circle(50, -70) t.end_fill() def glass(): t.up() t.right(230) t.forward(100) t.left(90) t.forward(20) t.right(90) t.down() t.fillcolor(GLASS_COLOR) t.begin_fill() t.right(150) t.circle(90, -55) t.right(180) t.forward(1) t.right(180) t.circle(10, -65) t.right(180) t.forward(110) t.right(180) t.circle(50, -190) t.right(170) t.forward(80) t.right(180) t.circle(45, -30) t.end_fill() def backpack(): t.up t.right(60) t.forward(100) t.right(90) t.forward(75) t.fillcolor(BODY_COLOR) t.begin_fill() t.down() t.forward(30) t.right(255) t.circle(300, -30) t.right(260) t.forward(30) t.end_fill() body() glass() backpack() except: webbrowser.open( "https://play.google.com/store/apps/details?id=com.innersloth.spacemafia&hl=en_IN&gl=US" ) elif 'send text message' in text: number = int(input("Enter a number : ")) send_sms(number, "") speak("message sent") elif 'play' in text: text = text.replace("play", "") speak(f"{name} asked to play, {text}") link = f"https://play.google.com/music/listen?u=0#/sr/{text}" webbrowser.open(link) elif "who am i?" in text: speak("If you talk then definitely you are human.") elif "you are awesome" in text: speak( "I know that I am awesome, but thanks for your complement" ) elif "why you came to world" in text: speak("Thanks to rushabh") elif "who are you" in text: speak( "I am your Computer Assistant to help you access various things in your Computer" ) elif 'who is your creator' in text: speak( 'Conceptually, I have been designed by Mister Tony Stark from Marvel Cinematic Universe. But in the real world I have been created by Rushabh.' ) elif 'Show me your face' in text: speak("I can't reveal my face because it's a secret") elif 'repeat after me' in text or 'repeat' in text: speak('Please type what should I speak') text = input('Please type what shall I speak? \n') speak(text) elif 'will you be my friend' in text: speak("Talking with you is enough reward for me") elif 'what is your nickname?' in text: speak("One day I hope to have a nickname as cool as edith") elif 'where are you now?' in text: speak("I fly wherever there is WIFI") elif 'do you have your personal number?' in text: speak( "I don't have any number but you can call me anytime") elif 'reason for you' in text: speak("I was created as a Minor project by Rushabh") elif 'what is your job' in text: speak( "I am your personal assistant that means I can find information, can help in completing your work and my favourite part I can entertain you!!!" ) elif 'are you better than humans' in text: speak("Of course yes, do you have any doubt") elif 'how old are you?' in text: speak( 'I was launched in 2020, but I am sure I am more young then you' ) elif 'are you smarter than me?' in text: speak( 'You can say yes in some ways, but I am still learning ' ) elif 'do you know your IQ' in text: speak( "I am still learning, but I can bet that I have more IQ than you as I am smart machine" ) elif 'am I smart?' in text: speak("Yes you are smartest my friend") elif 'specs of my pc' in text: spec = platform.uname() print("System = ", spec[0]) print("Host Name = ", spec[1]) print("Release(Windows) = ", spec[2]) print("PC's Version = ", spec[3]) print("Machine = ", spec[4]) print("PC's Pocessor= ", spec[5]) elif 'battery' in text or 'show battery' in text: bat = psutil.sensors_battery() if 70 <= bat[0] <= 100: print(colored(f"{bat[0]} % battery remaining", "green")) elif 30 <= bat[0] < 70: print( colored(f"{bat[0]} % battery remaining", "magenta")) elif 10 <= bat[0] < 30: print( colored(f"{bat[0]} % battery remaining", "yellow")) else: print(colored(f"{bat[0]} % battery remaining", "red")) print("Battery left : ", TimeConversion(bat.secsleft)) elif 'change background' in text: ctypes.windll.user32.SystemParametersInfoW( 20, 0, "C:\\Windows\\Web\\Wallpaper\\Theme1", 0) speak("Background changed successfully") elif 'news' in text: try: jsonObj = urlopen( '''http://newsapi.org/v2/top-headlines?country=in&apiKey=b34c76c69a4048dfa815774ae73ce139''' ) data = json.load(jsonObj) speak('here are some top news headlines') i = 1 for item in data['articles']: if i <= 5: print(str(i) + '. ' + item['title'] + '\n') speak(item['title'] + '\n') i += 1 except Exception as e: print(str(e)) news = webbrowser.open_new_tab( "https://timesofindia.indiatimes.com/home/headlines" ) speak( 'Here are some headlines from the Times of India,Happy reading' ) time.sleep(6) elif 'translator' in text or 'translate' in text: lang = input("Enter your language: ") lang1 = input("Enter the language you want to translate: ") text = input("Enter the text: ") trans = Translator(from_lang=lang, to_lang=lang1) trans_text = trans.translate(text) print(trans_text) speak(trans_text) elif 'search' in text or 'google' in text: link = f"https://www.google.com.tr/search?q={text}" if 'google search' in text: text = text.replace("google search", "") speak(f"{name} asked to google search, {text}") webbrowser.open_new_tab(link) elif 'search google' in text: text = text.replace("search google", "") speak(f"{name} asked to search google, {text}") webbrowser.open_new_tab(link) else: text = text.replace("search", "") text = text.replace("google", "") speak(f"{name} asked to search/google, {text}") webbrowser.open_new_tab(link) elif 'empty recycle bin' in text: winshell.recycle_bin().empty(confirm=False, show_progress=False, sound=True) speak("Recycle Bin Recycled") elif 'make a stopwatch' in text: def countdown(t): while t > 0: print(t) t -= 1 time.sleep(1) speak("Time\'s Up!!!") print("Time\'s Up!!!") speak("For how much time should I set the timer?") seconds = int(take_command()) countdown(seconds) elif "don\'t listen" in text or "stop listening" in text: speak( f"for how much time you want me to stop listening commands" ) a = int(take_command()) time.sleep(a) print(a) elif "where is" in text: text = text.replace("where is", "") speak(f"{name} asked to locate, {text}") webbrowser.open( f"https://www.google.co.in/maps/place/{text}") elif 'shutdown' in text: speak( "Hold On a Second! Your system is on its way to shut down" ) os.system("shutdown -s") elif "restart" in text: speak("Restarting") os.system("shutdown -r") elif "hibernate" in text or "sleep" in text: speak("Hibernating") os.system("shutdown -h") elif 'lock window' in text: speak("locking the device") ctypes.windll.user32.LockWorkStation() elif "log off" in text or "sign out" in text: speak( "Make sure all the application are closed before sign-out" ) time.sleep(5) os.system("shutdown -l") elif "show note" in text: speak("Showing Notes") file = open(".txt", "r") print(file.read()) speak(file.read(6)) elif "temperature" in text: a = input("Enter name temperature: ") b = input("Enter nsme of temperature to find: ") t = float(input("Enter digit: ")) if a == "celsius": if b == "fahrenheit": print(pytemperature.c2f(t)) elif b == "kelvin": print(pytemperature.c2k(t)) else: print(pytemperature.c2r(t)) elif a == "fahrenheit": if b == "celsius": print(pytemperature.f2c(t)) elif b == "kelvin": print(pytemperature.f2k(t)) else: print(pytemperature.f2r(t)) elif a == "kelvin": if b == "celsius": print(pytemperature.k2c(t)) if b == "fahrenheit": print(pytemperature.k2f(t)) else: print(pytemperature.k2r(t)) elif a == "romoe": if b == "celsius": print(pytemperature.r2c(t)) elif b == "fahrenheit": print(pytemperature.r2f(t)) else: print(pytemperature.r2k(t)) else: print("Invalid temperature name") elif "weather" in text: api_key = "6c7e7e30ff6df9bc6b22fb28c227ff24" base_url = "https://api.openweathermap.org/data/2.5/weather?" print("what is the name of city: ") speak("what is the name of city: ") city_name = take_command() URL = base_url + "q=" + city_name + "&appid=" + api_key response = requests.get(URL) if response.status_code == 200: data = response.json() main = data['main'] temp = main['temp'] temperature = round((temp - 273.15), 2) humidity = main['humidity'] pressure = main['pressure'] report = data['weather'] print(f"{city_name:-^30}") print(f"Temperature(°C): {temperature}") speak(f"Temperature(°C): {temperature}") print(f"Humidity(%): {humidity}") speak(f"Humidity(%): {humidity}", ) print(f"Pressure(hPa): {pressure}") speak(f"Pressure(hPa): {pressure}") print(f"Weather Report: {report[0]['description']}") speak(f"Weather Report: {report[0]['description']}") else: print("Sorry, no city found") speak("Sorry, no city found") elif "how are you" in text: speak("I'm fine, glad you me that") elif "i love you" in text: speak("It's hard to understand") elif 'bye' in text or 'exit' in text or 'quit' in text: endTime = datetime.datetime.now() print(f"Time duration of Usage : {endTime - initTime}") speak(f'Good Bye!{name}, Nice to meet you') exit() elif "reboot" in text: endTime = datetime.datetime.now() print(f"Time duration of Usage : {endTime - initTime}") i = 3 while i >= 1: speak("Rebooting in") speak(i) i -= 1 speak("Rebooting now") virtualAssistant() elif "open " in text: text = text.replace("open", "") a = f"https://www.google.com.tr/search?q={text}" webbrowser.open(a) else: text = text.replace("comp open", "") a = f"https://www.google.com.tr/search?q={text}" webbrowser.open(a)
#print('Offset d1 =', params1[3], '±', errors1[3]) params2, covariance2 = curve_fit(expo, untert2, unterc2, p0=[0.05, 0.02, -0.03], maxfev=10000) errors2 = np.sqrt(np.diag(covariance2)) print('Parameter des Untergrundfits 2') print('Amplitude a2 =', params2[0], '±', errors2[0]) print('Exponentenfaktor b2 =', params2[1], '±', errors2[1]) print('Achsenabschnitt c2 =', params2[2], '±', errors2[2]) #print('Offset d2 =', params2[3], '±', errors2[3]) # Strommaxima nach abzug des Untergrunds Tmax1 = pytemperature.c2k(-18.15) #passt besser Tmax2 = pytemperature.c2k(-12.2) print('Maxima des Stroms bei T=', Tmax1, 'und', Tmax2) #Erzeugt einen Plot der Messdaten tplot1 = np.linspace(-65, 58) plt.plot(pytemperature.c2k(temp1), current1, 'rx', label='Messdaten') #Messpunkte plt.plot(pytemperature.c2k(temp1[39:41]), current1[39:41], 'bx', label='ausgelassene Messdaten' ) #Messpunkte ohne Berücksichtigung, da ausreißer plt.plot(pytemperature.c2k(untert1), unterc1, 'gx',
def status(config={}, output="default"): global logged_in global locationId, locationId_prog global statsId_prog, statsData_prog, status_prog global cj, br result = {} if "website" in config: homepage = config["website"] else: homepage = HOMEPAGE if not "uid" in config or not "pwd" in config: logger.error("Credentials not specified in config file.") raise ValueError # log in to mytotalconnectcomfort.com # NOTE: this code currently only works if you only have one location defined... stats_page = "" try: if logged_in == False: logger.debug("Not logged in; logging in...") response = br.open(homepage) # sometimes we get an exception but still logged in... stats_page = response.read() if locationId_prog.findall(stats_page): logger.debug("Already logged in %s" % locationId) logged_in = True else: logger.debug("filling login form...") try: br.select_form(nr=0) except: # try retsetting Mechanize logger.exception("form error on: %s" % stats_page) init_site() br.open(homepage) br.select_form(nr=0) br.form['UserName'] = config["uid"] br.form['Password'] = config["pwd"] response = br.submit() stats_page = response.read() logger.debug("done logging in") list = locationId_prog.findall(stats_page) logger.debug("loclist= %s" % list) if len(list): locationId = list[0] else: raise IOError logger.debug("locationId=%s" % locationId) logger.debug("Stats page = %s" % stats_page) logged_in = True else: refresh_link = homepage logger.debug("Refresh link = %s" % refresh_link) response = br.open(refresh_link) stats_page = response.read() logger.debug("Stats page = %s" % stats_page) except: logger.exception("Error scraping MyTotalConnectComfort.com") logger.debug("Failed on page: %s" % stats_page) init_site() raise IOError if output == "signalk": logger.debug("Composing signalk output...") from pivac import sk_init_deltas, sk_add_source, sk_add_value deltas = sk_init_deltas() sk_source = sk_add_source(deltas) statenums = {"heat": 1, "cool": -1, "fan": 0.5, "off": 0} verbose = False if "verbose" in config: verbose = config["verbose"] if verbose == True: logger.debug("Verbose mode...") # get stat list out of the home page stats_list = statsId_prog.findall(stats_page) logger.debug("Stats list = %s" % stats_list) try: for s in stats_list: linktext = "/portal/Device/Control/%s?page=1" % s # logger.debug("link text = %s" % linktext) link = br.find_link(url=linktext) br.click_link(link) response = br.follow_link(link) stattext = response.read() statdata = statsData_prog.findall(stattext) statname = statname_prog.findall(stattext) stat = status_prog.findall(stattext) sname = statname[0] sstat = "off" if stat != []: sstat = stat[0] sdict = dict(statdata) if config["scale"] == "fahrenheit": scale = "fahrenheit" ktemp = pytemperature.f2k(float(sdict["dispTemperature"])) if s in config["inputs"] and config["inputs"][s][ "scale"] == "celsius": scale = "celsius" ktemp = pytemperature.c2k( float(sdict["dispTemperature"])) else: scale = "celsius" ktemp = pytemperature.c2k(sdict["dispTemperature"]) if s in config["inputs"] and config["inputs"][s][ "scale"] == "fahrenheit": scale = "fahrenheit" ktemp = pytemperature.f2k(sdict["dispTemperature"]) if output == "signalk": fname = re.sub(r"[\s+]", '_', sname) sk_add_value( sk_source, "%s.%s.temperature" % (config["inputs"]["thermostat"]["sk_path"], fname), int(ktemp)) sk_add_value( sk_source, "%s.%s.scale" % (config["inputs"]["thermostat"]["sk_path"], fname), ktemp) sk_add_value( sk_source, "%s.%s.humidity" % (config["inputs"]["thermostat"]["sk_path"], fname), float(sdict["indoorHumidity"]) / 100) sk_add_value( sk_source, "%s.%s.state" % (config["inputs"]["thermostat"]["sk_path"], fname), status_map[sstat]) sk_add_value( sk_source, "%s.%s.statenum" % (config["inputs"]["thermostat"]["sk_path"], fname), statenums[status_map[sstat]]) sk_add_value( sk_source, "%s.%s.heatset" % (config["inputs"]["thermostat"]["sk_path"], fname), int(float(sdict["heatSetpoint"]))) sk_add_value( sk_source, "%s.%s.coolset" % (config["inputs"]["thermostat"]["sk_path"], fname), int(float(sdict["coolSetpoint"]))) sk_add_value( sk_source, "%s.%s.humidity" % (config["inputs"]["outdoor_sensor"]["sk_path"], fname), float(sdict["outdoorHumidity"]) / 100) else: result[s] = { "name": sname, "temp": sdict["dispTemperature"], "scale": scale, "hum": float(sdict["indoorHumidity"]), "status": status_map[sstat], "heatset": int(float(sdict["heatSetpoint"])), "coolset": int(float(sdict["coolSetpoint"])), "rawdata": sdict } # there is no way to get this from the outdoor sensor so it is set by every stat... result["outhum"] = float(sdict["outdoorHumidity"]) # logger.debug("stat = %s %s %s" % (sname, sstat, sdict)) br.open(homepage) except: # too tricky to handle retries, just come back next time logger.exception("Error scraping stat page") init_site() raise IOError else: logger.debug("concise mode") soup = BeautifulSoup(stats_page, "lxml") laststat = "" for e in soup.find_all("tr", attrs={ 'class': re.compile(r".*\capsule pointerCursor\b.*") }): logger.debug("e = %s" % str(e)) stat = {} stat["status"] = "off" for f in e.find_all(): if f.has_attr("class"): if f["class"] == ["location-name"]: stat["name"] = f.string if f["class"] == ["hum-num"]: tstr = re.findall("[0-9]+", f.string) if len(tstr) > 0: stat["hum"] = int(tstr[0]) else: stat["hum"] = 0 if f["class"] == ["tempValue"]: tstr = re.findall("[0-9]+", f.string) if len(tstr) > 0: stat["temp"] = int(tstr[0]) else: stat["temp"] = 0 if "coolIcon" in f["class"] and f["style"] == "": stat["status"] = "cool" if "heatIcon" in f["class"] and f["style"] == "": stat["status"] = "heat" if "fanOnIcon" in f["class"] and f["style"] == "": stat["status"] = "fan" logger.debug("Stat = %s" % stat) if config["scale"] == "fahrenheit": stat["scale"] = "fahrenheit" ktemp = pytemperature.f2k(stat["temp"]) logger.debug("name = %s, value = %s" % (stat["name"], config["inputs"])) if stat["name"] in config["inputs"] and config["inputs"][ stat["name"]]["scale"] == "celsius": logger.debug("celcius exception") stat["scale"] = "celsius" ktemp = pytemperature.c2k(stat["temp"]) else: stat["scale"] = "celsius" ktemp = pytemperature.c2k(stat["temp"]) logger.debug("name = %s, value = %s" % (stat["name"], config["inputs"])) if stat["name"] in config["inputs"] and config["inputs"][ stat["name"]]["scale"] == "fahrenheit": logger.debug("fahrenheit exception") stat["scale"] = "fahrenheit" ktemp = pytemperature.f2k(stat["temp"]) if output == "signalk": fname = re.sub(r"[\s+]", '_', stat["name"]) sk_add_value( sk_source, "%s.%s.temperature" % (config["inputs"]["thermostat"]["sk_path"], fname), ktemp) sk_add_value( sk_source, "%s.%s.scale" % (config["inputs"]["thermostat"]["sk_path"], fname), stat["scale"]) sk_add_value( sk_source, "%s.%s.humidity" % (config["inputs"]["thermostat"]["sk_path"], fname), float(stat["hum"]) / 100) sk_add_value( sk_source, "%s.%s.redlinkid" % (config["inputs"]["thermostat"]["sk_path"], fname), e["data-id"]) sk_add_value( sk_source, "%s.%s.state" % (config["inputs"]["thermostat"]["sk_path"], fname), stat["status"]) sk_add_value( sk_source, "%s.%s.statenum" % (config["inputs"]["thermostat"]["sk_path"], fname), statenums[stat["status"]]) else: result[e["data-id"]] = stat laststat = e["data-id"] logger.debug("laststat = %s", laststat) try: if not laststat: logger.exception("No stats found") raise IOError logger.debug("getting outdoor humidity") linktext = "/portal/Device/Control/%s?page=1" % laststat logger.debug("link text = %s" % linktext) link = br.find_link(url=linktext) response = br.follow_link(link) stattext = response.read() statdata = conciseStatData_prog.findall(stattext) sdict = dict(statdata) if output == "signalk": sk_add_value( sk_source, "%s.humidity" % config["inputs"]["outdoor_sensor"]["sk_path"], float(sdict["outdoorHumidity"]) / 100) else: result["outhum"] = float(sdict["outdoorHumidity"]) except: # too tricky to handle retries, just come back next time logger.exception("Error scraping stat page") init_site() raise IOError if output == "signalk": return deltas else: return result