コード例 #1
0
def temperatures_to_celsius(entry):
    print(entry)
    if (entry['avg'] is None):
        return entry

    return {
        "date": entry['date'],
        "min": round(pytemperature.f2c(entry['min'])),
        "avg": round(pytemperature.f2c(entry['avg'])),
        "max": round(pytemperature.f2c(entry['max']))
    }
コード例 #2
0
 def iat(self):
     # return units: celsius and fahrenheit
     temperature = [
         302, 302, 298, 294, 289, 285, 282, 278, 273, 269, 266, 262, 258,
         253, 249, 246, 242, 239, 235, 231, 226, 222, 219, 215, 212, 208,
         206, 203, 201, 199, 197, 194, 192, 190, 188, 185, 183, 181, 179,
         177, 177, 176, 174, 172, 170, 168, 167, 165, 165, 163, 161, 159,
         158, 158, 156, 156, 154, 152, 152, 150, 149, 149, 147, 147, 145,
         143, 143, 141, 141, 140, 138, 138, 136, 134, 134, 132, 132, 131,
         131, 129, 129, 127, 127, 125, 125, 125, 123, 123, 122, 122, 122,
         120, 120, 118, 118, 116, 116, 116, 114, 114, 113, 113, 111, 111,
         111, 109, 109, 107, 107, 107, 105, 105, 104, 104, 102, 102, 102,
         100, 100, 98, 98, 96, 96, 96, 95, 95, 93, 93, 91, 91, 91, 89, 89,
         87, 87, 87, 86, 86, 84, 84, 82, 82, 82, 80, 80, 78, 78, 77, 77, 77,
         75, 75, 73, 73, 73, 71, 71, 69, 69, 68, 68, 68, 66, 66, 64, 64, 62,
         62, 62, 60, 60, 59, 59, 57, 57, 57, 55, 55, 53, 53, 53, 51, 51, 50,
         50, 48, 48, 48, 46, 46, 44, 44, 42, 42, 42, 41, 41, 39, 39, 39, 37,
         37, 35, 35, 33, 33, 32, 32, 30, 30, 28, 26, 26, 24, 24, 23, 21, 21,
         19, 19, 17, 15, 15, 14, 14, 12, 10, 10, 8, 8, 6, 5, 3, 1, 0, -4,
         -5, -7, -9, -11, -13, -14, -18, -20, -22, -23, -25, -27, -31, -32,
         -34, -38, -40, -40, -40, -40
     ]
     try:
         if self.version == 23:
             index = KPRO23_IAT
         elif self.version == 4:
             index = KPRO4_IAT
         else:
             return {'celsius': 0, 'fahrenheit': 0}
         iat_fahrenheit = temperature[self.data1[index]]
         iat_celsius = pytemperature.f2c(iat_fahrenheit)
         return {'celsius': iat_celsius, 'fahrenheit': iat_fahrenheit}
     except IndexError:
         return {'celsius': 0, 'fahrenheit': 0}
コード例 #3
0
ファイル: kpro.py プロジェクト: pablobuenaposada/HonDash
 def iat(self):
     """
     Intake air temperature
     """
     # return units: celsius and fahrenheit
     temperature = [302, 302, 298, 294, 289, 285, 282, 278, 273, 269, 266, 262, 258, 253, 249, 246, 242, 239, 235,
                    231, 226, 222, 219, 215, 212, 208, 206, 203, 201, 199, 197, 194, 192, 190, 188, 185, 183, 181,
                    179, 177, 177, 176, 174, 172, 170, 168, 167, 165, 165, 163, 161, 159, 158, 158, 156, 156, 154,
                    152, 152, 150, 149, 149, 147, 147, 145, 143, 143, 141, 141, 140, 138, 138, 136, 134, 134, 132,
                    132, 131, 131, 129, 129, 127, 127, 125, 125, 125, 123, 123, 122, 122, 122, 120, 120, 118, 118,
                    116, 116, 116, 114, 114, 113, 113, 111, 111, 111, 109, 109, 107, 107, 107, 105, 105, 104, 104,
                    102, 102, 102, 100, 100, 98, 98, 96, 96, 96, 95, 95, 93, 93, 91, 91, 91, 89, 89, 87, 87, 87, 86,
                    86, 84, 84, 82, 82, 82, 80, 80, 78, 78, 77, 77, 77, 75, 75, 73, 73, 73, 71, 71, 69, 69, 68, 68,
                    68, 66, 66, 64, 64, 62, 62, 62, 60, 60, 59, 59, 57, 57, 57, 55, 55, 53, 53, 53, 51, 51, 50, 50,
                    48, 48, 48, 46, 46, 44, 44, 42, 42, 42, 41, 41, 39, 39, 39, 37, 37, 35, 35, 33, 33, 32, 32, 30,
                    30, 28, 26, 26, 24, 24, 23, 21, 21, 19, 19, 17, 15, 15, 14, 14, 12, 10, 10, 8, 8, 6, 5, 3, 1, 0,
                    -4, -5, -7, -9, -11, -13, -14, -18, -20, -22, -23, -25, -27, -31, -32, -34, -38, -40, -40, -40,
                    -40]
     try:
         if self.version == constants.KPRO23_ID:
             index = constants.KPRO23_IAT
         elif self.version == constants.KPRO4_ID:
             index = constants.KPRO4_IAT
         else:
             return {'celsius': 0, 'fahrenheit': 0}
         iat_fahrenheit = temperature[self.data1[index]]
         iat_celsius = pytemperature.f2c(iat_fahrenheit)
         return {'celsius': iat_celsius, 'fahrenheit': iat_fahrenheit}
     except IndexError:
         return {'celsius': 0, 'fahrenheit': 0}
コード例 #4
0
def index():
    if request.method == 'POST':
        new_city = request.form.get('city')

        if new_city:
            new_city_obj = City(name=new_city)

            db.session.add(new_city_obj)
            db.session.commit()

    cities = City.query.all()

    url = 'http://api.openweathermap.org/data/2.5/weather?q={}&units=imperial&appid=271d1234d3f497eed5b1d80a07b3fcd1'

    weather_data = []

    for city in cities:

        r = requests.get(url.format(city.name)).json()
        t = pytemperature.f2c(r['main']['temp'])
        temp = round(t)

        weather = {
            'city': city.name,
            'temperature': temp,
            'description': r['weather'][0]['description'],
            'icon': r['weather'][0]['icon'],
        }

        weather_data.append(weather)

    return render_template('weather.html', weather_data=weather_data)
コード例 #5
0
def get_weather_data(hava_response, pp=False):
    hava_soup = bs4.BeautifulSoup(hava_response.text, "html.parser")

    now_soup = hava_soup.find(class_="temperature").find(class_="now")

    derece = now_soup.find("span").text
    olcek = now_soup.find(class_="unit-control").find("button").text

    if olcek.lower() == "f":
        celcius_derece = int(pytemperature.f2c(int(derece)))
    elif olcek.lower() == "c":
        celcius_derece = int(derece)
    else:
        raise ValueError(
            "Yahoo'nun gösterdiği sıcaklık ölçeği celcius ya da fahreneit değil"
        )

    if pp:
        import sys
        if sys.version_info[:2] >= (3, 6):
            print(f"{celcius_derece:d}C°")
        else:
            print("{:d} C°".format(celcius_derece))
    else:
        return {"degree": derece, "scale": "C"}
コード例 #6
0
def get_weather_data_xpath(hava_response, pp=False):
    element_tree = lxml.html.fromstring(hava_response.text)
    root_element_xpath = "/html/body/div[1]/div/div[1]/div/div[4]/div[1]" \
                         "/div/div[2]/div/div/div/div/section[2]/div/div[3]"

    temp_elements = element_tree.xpath(root_element_xpath + "/span[1]")
    deg_elements = element_tree.xpath(root_element_xpath + "/div/button[1]")

    if temp_elements:
        temp_element = temp_elements[0]
    else:
        raise ValueError("Sıcaklık elementini bulamadık")

    if deg_elements:
        deg_element = deg_elements[0]
    else:
        raise ValueError("Ölçek elementini bulamadık")

    derece = temp_element.text
    olcek = deg_element.text

    if olcek.lower() == "f":
        celcius_derece = int(pytemperature.f2c(int(derece)))
    elif olcek.lower() == "c":
        celcius_derece = int(derece)
    else:
        raise ValueError(
            "Yahoo'nun gösterdiği sıcaklık ölçeği celcius ya da fahreneit değil"
        )

    if pp:
        import sys
        if sys.version_info[:2] >= (3, 6):
            print(f"{celcius_derece:d}C°")
        else:
            print("{:d} C°".format(celcius_derece))
    else:
        return {"degree": celcius_derece, "scale": "C"}
コード例 #7
0
def profile(request):
    if not request.user.is_authenticated():
        return render(request, 'login.html')
    user = User.objects.get(id=request.user.id)
    customer = Customer.objects.get(user_id=user.id)
    city = "Raipur"
    results = get_weather(city)
    date = results['query']['results']['channel'][0]['item']['condition'][
        'date']
    temp = pytemperature.f2c(
        int(results['query']['results']['channel'][0]['item']['condition']
            ['temp']))
    text = results['query']['results']['channel'][0]['item']['condition'][
        'text']
    weather_img = Weather.objects.get(type=text)
    weather = {}
    weather['date'] = date
    weather['temp'] = temp
    weather['text'] = text
    orders = Order.objects.filter(customer__user_id=request.user.id)
    yourorder = orders.order_by('-created')
    customer = Customer.objects.get(user_id=request.user.id)
    items = Cart.objects.filter(customer_id=customer.id, status=0)
    total = 0
    for c in items:
        total = total + c.total_price

    return render(
        request, 'user_panel/profile.html', {
            'weather': weather,
            'weather_img': weather_img,
            'orders': yourorder,
            'items': items,
            'total': total,
            'customer': customer
        })
コード例 #8
0
import pytemperature
import wget
# wget.download("https://raw.githubusercontent.com/pesikj/python-012021/master/zadani/5/temperature.csv")
teploty = pandas.read_csv("temperature.csv")
teploty = teploty.set_index("City")

print(teploty.head())
print(teploty.loc["Prague"])
nad_osmdesat = teploty[teploty["AvgTemperature"] > 80]
print(nad_osmdesat)
evropa_nad_sedesat = teploty[(teploty["AvgTemperature"] > 60)
                             & (teploty["Region"] == "Europe")]
print(evropa_nad_sedesat)
extremni_hodnoty = teploty[(teploty["AvgTemperature"] > 80) |
                           (teploty["AvgTemperature"] < -20)]
print(extremni_hodnoty)

# pokročilá varianta:
teploty["AvgTemperatureCelsia"] = pytemperature.f2c(teploty["AvgTemperature"])
nad_tricet = teploty[teploty["AvgTemperatureCelsia"] > 30]
print(nad_tricet)
evropa_nad_patnact = teploty[(teploty["AvgTemperatureCelsia"] > 15)
                             & (teploty["Region"] == "Europe")]
print(evropa_nad_patnact)
extremni_hodnoty = teploty[(teploty["AvgTemperatureCelsia"] > 30) |
                           (teploty["AvgTemperatureCelsia"] < -10)]
print(extremni_hodnoty)
# zdá se, že je chyba v některých hodnotách - nevidim tady celou tabulku, ale zřejmě jde o některé státy Afriky
podezrele_hodnoty = teploty[teploty["AvgTemperatureCelsia"] < -40]
print(podezrele_hodnoty)
# hm, tak koukám, že jsou ta data asi velmi chybová a nesmyslné hodnoty se vyskytují i v Asii
コード例 #9
0
"""
Temperature Conversions as functions
Two functions f2c and c2f:
Write a program that converts between the two
T(°C) = (T(°F) - 32) × 5/9
T(°F) = T(°C) × 9/5 + 32
"""
import pytemperature as pt

pt = 5

try:
    temp = int(input("Please enter a temperature: "))
    corf = input("C/F")

    if corf == "C":
        ftem = pt.c2f(temp)
        print("The F: {}".format(ftem))
    if corf == "F":
        ctem = pt.f2c(temp)
        print("The celcius: {}".format(ctem))
except:
    print("Please enter a valid number ")
コード例 #10
0
ファイル: priklad24.py プロジェクト: Hedwika/python-012021
print(temperature.head())

prague = temperature[(temperature["City"] == "Prague")]
print(prague)

more_than_eighty = temperature[(temperature["AvgTemperature"] > 80)]
print(more_than_eighty)

more_than_sixty_europe = temperature[(temperature["AvgTemperature"] > 60)
                                     & (temperature["Region"] == "Europe")]
print(more_than_sixty_europe)

extreme = temperature[(temperature["AvgTemperature"] < -20) |
                      (temperature["AvgTemperature"] > 80)]
print(extreme)

temperature["AvgTemperatureCelsius"] = pytemperature.f2c(
    temperature["AvgTemperature"])

more_than_thirty_celsius = temperature[(temperature["AvgTemperatureCelsius"] >
                                        30)]
print(more_than_thirty_celsius)

more_than_fifteen_celsius_europe = temperature[
    (temperature["AvgTemperatureCelsius"] > 15)
    & (temperature["Region"] == "Europe")]
print(more_than_fifteen_celsius_europe)

extreme_c = temperature[(temperature["AvgTemperatureCelsius"] > 30) |
                        (temperature["AvgTemperature"] < -10)]
print(extreme_c)
コード例 #11
0
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)
コード例 #12
0
ファイル: Priklad35.py プロジェクト: starkroman/python-012021
Vrať se k práci se souborem temperature.csv, který obsahuje informace o průměrné teplotě v různých městech v listopadu 2017.
- Vytvoř tabulku, která bude obsahovat údaje o teplotě za města Helsinki, Miami Beach a Tokyo.
- Vrať se k práci se souborem temperature.csv, který obsahuje informace o průměrné teplotě v různých
městech v listopadu 2017.
'''

import wget
import pandas as pd
import pytemperature
import matplotlib.pyplot as plt
import numpy

teploty = pd.read_csv('temperature.csv')
#print(teploty.head())

teploty['AVG_ve_stupnich_Celsia'] = pytemperature.f2c(
    teploty['AvgTemperature'])
print(teploty.head())

helsinki = teploty[teploty['City'] == 'Helsinki']
helsinki = helsinki['AVG_ve_stupnich_Celsia']
#print(helsinki.head())
tokyo = teploty[teploty['City'] == 'Tokyo']
tokyo = tokyo['AVG_ve_stupnich_Celsia']
#print(tokyo.head())
miami = teploty[teploty['City'] == 'Miami Beach']
miami = miami['AVG_ve_stupnich_Celsia']
#print(miami.head())

# převod na list teplot
helsinki_List = helsinki.to_numpy().tolist()
tokyo_List = tokyo.to_numpy().tolist()
コード例 #13
0
import pandas as pd
import pytemperature
#import wget

#wget.download("https://raw.githubusercontent.com/pesikj/python-012021/master/zadani/5/temperature.csv")
teploty = pd.read_csv("temperature.csv")
teploty = teploty.rename(columns={
    "Unnamed: 0": "id",
    "AvgTemperature": "Avg_Fahrenheit"
})
teploty["Avg_Celsia"] = pytemperature.f2c(teploty["Avg_Fahrenheit"])
print(teploty.info)

# Vyšší než 30 C
mereni_30 = teploty[teploty["Avg_Celsia"] > 30]
print("Více než 30 C:")
print(mereni_30)

# Vyšší než 15 C a v Evropě
mereni_15_E = teploty[(teploty["Avg_Celsia"] > 15)
                      & (teploty["Region"] == "Europe")]
print("Více než 15 C a v Evropě:")
print(mereni_15_E)

# Vyšší než 30 C a nižší než -10
mereni_ext = teploty[(teploty["Avg_Celsia"] > 30) |
                     (teploty["Avg_Fahrenheit"] < -10)]
print("Extrémy: více než 30 C a méně než -10 C:")
print(mereni_ext)

# Vypiš podezřelé -72.78 (zřejmě nezadány)
コード例 #14
0
# Dotaz na měření, ve kterých je teplota (sloupec AvgTemperature) vyšší než 80 stupňů.
print(data[average >= 80][temp], "\n")

# Dotaz na měření, ve kterých je teplota vyšší než 60 stupňů a současně bylo měření provedeno v regionu (sloupec Region) Evropa (Europe).
print(data[(average >= 60) & (data['Region'] == 'Europe')][temp], "\n")

# Dotaz na extrémní hodnoty, tj. měření, ve kterých je teplota vyšší než 80 stupňů nebo menší než - 20 stupňů.
print(data[(average >= 80) | (average <= -20)][temp], "\n")
"""
Nainstaluj si modul pytemperature a zkus si vytvořit nový sloupec, který bude obsahovat průměrnou templotu ve stupních Celsia. 
Ve svém programu nejprve proveď import modulu pytemperature. 
Nový sloupec pak přidáš do tabulky tak, že nalevo od = vložíš tabulku a název nového sloupce do hranatých závorek. 
Napravo pak můžeš provádět výpočty pomocí již existujících sloupců. 
Můžeš např. použít funkci f2c z modulu pytemperature, která převede teplotu ze stupňů Fahrenheita na stupně Celsia.
"""
data["AvgTemperatureCelsia"] = pytemperature.f2c(data["AvgTemperature"])

# Dotaz na měření, ve kterých je teplota (sloupec AvgTemperatureCelsia) vyšší než 30 stupňů Celsia.
print(
    data[data['AvgTemperatureCelsia'] >= 30][['City', 'AvgTemperatureCelsia']],
    "\n")

# Dotaz na měření, ve kterých je teplota vyšší než 15 stupňů Celsia
# a současně bylo měření provedeno v regionu (sloupec Region) Evropa (Europe).
print(
    data[(data['AvgTemperatureCelsia'] >= 15)
         & (data['Region'] == 'Europe')]['AvgTemperatureCelsia'], "\n")

# Dotaz na extrémní hodnoty, tj. měření, ve kterých je teplota vyšší než 30 stupňů Celsia nebo menší než -10 stupňů.
# Jsou některé hodnoty podezřelé?
print(
コード例 #15
0
def process_query(query):
    query_tokens = nltk.word_tokenize(query)
    #print query_tokens
    stop_words = set(nltk.corpus.stopwords.words('english'))
    #print stop_words
    filtered_query = [w for w in query_tokens if not w in stop_words]
    #print filtered_query
    tagged_query = nltk.pos_tag(filtered_query)
    #print tagged_query
    #ner_tagged_query = nltk.ne_chunk(tagged_query)
    #print ner_tagged_query
    #print type(ner_tagged_query)
    proper_nouns = []
    nouns = []
    verbs = []
    adjectives = []
    for i in range(0, len(tagged_query)):
        if 'NNP' == tagged_query[i][1]:
            proper_nouns.append(tagged_query[i][0])
        if 'NN' == tagged_query[i][1] or 'NNS' == tagged_query[i][1]:
            nouns.append(tagged_query[i][0])
        if 'J' in tagged_query[i][1]:
            adjectives.append(tagged_query[i][0])
        if 'V' in tagged_query[i][1]:
            verbs.append(tagged_query[i][0])
    #print proper_nouns
    #print verbs
    #print nouns
    #print adjectives
    target = 'null'
    print ""

    if (len(adjectives) > 0):
        #print "Computing similarity for words in " ,adjectives
        (target, t_word) = similarity.compute_similarity(adjectives)
    if target == 'null':
        if (len(nouns) > 0):
            #print "Computing similarity for words in " ,nouns
            (target, t_word) = similarity.compute_similarity(nouns)
    if target == 'null':
        if (len(verbs) > 0):
            #print "Computing similarity for words in " , verbs
            (target, t_word) = similarity.compute_similarity(verbs)

    #print (target,t_word)

    roi = []
    for x in adjectives + nouns + verbs + proper_nouns:
        if x == t_word:
            continue
        else:
            roi.append(x)

    #print "roi = ",roi
    #print "target = ",target

    if target == 'f':
        place = proper_nouns
        if (len(proper_nouns) == 0):
            #print "Place not recognized"
            #exit(0)
            place = roi
        print "Place: ", str(place[0])
        location = weather.lookup_by_location(str(place[0]))
        condition = location.condition()
        #print("In "+proper_nouns[0]+" it is currently: "+ condition.text())
        forecast = location.forecast()
        print "Date:", forecast[0].date()
        print "Condition:", forecast[0].text()
        print "Current:", str(pytemperature.f2c(int(condition.temp()))), "C"
        print "Highest:", str(pytemperature.f2c(int(forecast[0].high()))), "C"
        print "Lowest:", str(pytemperature.f2c(int(forecast[0].low()))), "C"

    elif target == 'h' or target == 'c' or target == 't':
        place = proper_nouns
        if (len(proper_nouns) == 0):
            #print "Place not recognized"
            #exit(0)
            place = roi
        print "Place: ", str(place[0])
        location = weather.lookup_by_location(str(place[0]))
        condition = location.condition()
        #print type(int(condition.temp()))
        print "In " + place[0] + ", the temperature is: " + str(
            pytemperature.f2c(int(condition.temp()))), "C"

    elif target == 'd':
        definitions = dictionary.meaning(str(roi[0]))
        for k, v in definitions.iteritems():
            for meanings in v:
                print meanings
        print wikipedia.summary(str(roi[0]))
        #roi_p = wikipedia.page(str(roi[0]))
        #print roi_p.content

    elif target == 's':
        syn = (dictionary.synonym(str(roi[0])))
        for i in syn:
            print i
        #todo synonyms
        #print "syn"
    elif target == 'a':
        ant = (dictionary.antonym(str(roi[0])))
        for i in ant:
            print i
        #todo antonyms
        #print "antonym"
    else:
        print "Can't process query"
        exit(0)