Ejemplo n.º 1
0
    def _btnClicked(self):
        """Insert data in database when OK button is clicked"""
        # Check if all fields were filled
        name = self.nameEntry.get().strip()
        start = self.startCombo.get()
        end = self.endCombo.get()
        day = self.dayCombo.get()
        type = self.typeCombo.get()

        # Check missing values
        if name == "" or start == "" or end == "" or day == "" or type == "":
            messagebox.showwarning("Missing fields!",
                                   "Please fill the missing fields!")
            return
        if type in Constants.TASKS[0:3]:
            subject = self.subjectCombo.get()
            if subject == "":
                messagebox.showwarning("Missing fields!",
                                       "Please fill the missing fields!")
                return
        else:
            subject = None

        # Check if starts earlier than end
        if Time.TIMELIST.index(start) >= Time.TIMELIST.index(end):
            messagebox.showwarning("Time error",
                                   "Make sure that time is correct!")
            return

        # Check time
        started = False
        index = 0
        for t in Time.HOURS:
            # Create an event for each hour
            if t[0:5] == start: started = True
            if t[8:] == end:
                started = False
                # Add one last event
                if subject == "":
                    event = Event(name, start, end, day, type)
                else:
                    event = Event(name, start, end, day, type, subject)
                Database.insert(day, index, event)

            if started:
                # Create the Event object
                if subject == "":
                    event = Event(name, start, end, day, type)
                else:
                    event = Event(name, start, end, day, type, subject)
                Database.insert(day, index, event)

            index += 1

        self.destroyFrame()
Ejemplo n.º 2
0
    def _addStudyToSchedule(self, subject, timerangeIndex, day):
        """
        Insert an event (study time) to database, given it's data

        :param subject: Subject of the event
        :param timerangeIndex: Index of Time.HOURS list
        :param day: Day of the event
        :return: None
        """
        event = Event("Study {}".format(subject),
                      Time.HOURS[timerangeIndex][:5],
                      Time.HOURS[timerangeIndex][9:], day, "Study", subject)
        Database.insert(day, timerangeIndex, event)
Ejemplo n.º 3
0
def collect_raw_data(log_info, api_key, base_url, city_name):
    """
    Collect environment variables from specified city based on
    openweathermap api.
    Args:
    ---------
        log_info: object used to storage log information
        api_key: login api key
        base_url: url of api
        city_name: name of the city
    Return:
    ---------
        nothing..
    """
    final_url = base_url + "appid=" +\
        api_key + "&q=" + city_name

    weather_data = requests.get(final_url).json()

    cities = []
    cities.append(
        Cidades(city_name, weather_data['coord']['lat'],
                weather_data['coord']['lon']))

    # INSERE SOMENTE UMA VEZ: REFATORAR!
    db = Database()
    # db.insert(cities)
    cidades = db.read(Cidades)

    # De tempos em tempos, ler os dados e povoar a base (a cada minuto)!
    start_time = time.time()
    while True:
        log_info.warning('Collecting data...')
        weather_data = requests.get(final_url).json()
        mtr_data = []
        mtr_data.append(
            Meteorologia(
                cidades[0].Id, datetime.now(), weather_data['clouds']['all'],
                weather_data['main']['humidity'],
                weather_data['main']['pressure'], weather_data['main']['temp'],
                weather_data['main']['feels_like'],
                weather_data['wind']['deg'], weather_data['wind']['speed']))
        db.insert(mtr_data)

        time.sleep(60.0 - ((time.time() - start_time) % 60.0))