Exemplo n.º 1
0
 def end_str(self, base=datetime.now()) -> str:
     """Returns a formatted string of the end date"""
     end_date = self.end()
     # use previous day if end of multi-day, all-day event
     if self.all_day() and not self.__one_day():
         end_date -= timedelta(days=1)
     return format_date(end_date, all_day=self.all_day(), base=base)
Exemplo n.º 2
0
def news_init(base, api):
    date = format_date()
    for keyword in keywords:
        news_list = search_news('us', None, keyword, api)
        for news in news_list:
            base.store_data("news", news, [date, keyword, news["publishedAt"]])
            print("==== News uploaded ====")
    return
Exemplo n.º 3
0
 def store_logs(self):
     if not os.path.exists(self.logs_file):
         stored_logs = []
     else:
         with open(self.logs_file, mode='r', encoding="utf-8") as f:
             stored_logs = json.load(f)
     today = format_date(datetime.datetime.today())
     today_logs = {"date": today, "logs": []}
     for member in self.members:
         item = {"name": member["name"], "log": member["log"]}
         today_logs["logs"].append(item)
     stored_logs.append(today_logs)
     with open(self.logs_file, mode='w', encoding="utf-8") as f:
         json.dump(stored_logs, f, ensure_ascii=False)
Exemplo n.º 4
0
def getWordCloud():
    """
    generate a wordcloud json and return to client
    """
    worddb = open(wordquerydb, "r")
    print("Word data opened for reading")
    wordcloud_data = json.load(worddb)
    worddb.close()
    print("Word data closed for reading")
    date_str = format_date()
    exact_date = [int(it) for it in date_str.split("-")]
    exact_date.append(0)
    word_list = []
    if date_str not in wordcloud_data.keys():
        word_list, frequency = word_count(firebase, end_time=exact_date)
        if (word_list[0]["word"] == ""):
            print("Find previous data")
            data_keys = wordcloud_data.keys()
            sorted_keys = sorted(
                data_keys,
                key=lambda x: int(x.split("-")[1]) * 30 * 24 + int(
                    x.split("-")[2]) * 24 + int(x.split("-")[3]),
                reverse=True)
            word_list = wordcloud_data[sorted_keys[0]]
        else:
            wordcloud_data[date_str] = word_list
            worddb = open(wordquerydb, "w")
            print("Word data opened for writing")
            json.dump(wordcloud_data, worddb)
            worddb.close()
            print("Word data closed for writing")
    else:
        word_list = wordcloud_data[date_str]
    new_wordcloud = {'words': []}
    for word in word_list:
        new_wordcloud["words"].append({
            'text':
            word["word"].upper(),
            'value':
            int((word["frequency"] + 50) / 2)
        })
    new_wordcloud["words"] = new_wordcloud["words"][0:200]
    print(json.dumps(new_wordcloud, indent=2))
    return json.dumps(new_wordcloud)
Exemplo n.º 5
0
    def get(self):
        try:
            query_params = self.request.arguments
            start_date = utils.get_date(query_params['from'][0])
            end_date = utils.get_date(query_params['to'][0])
        except:
            self.set_status(400)
            self.finish()
            return

        try:
            accts = AccountBalances()
            net_worths = [{'date': utils.format_date(date), 'net-worth': net_worth}
                          for (date,net_worth) in accts.net_worths(start_date,end_date)]
            self.write(escape.json_encode(net_worths))
            self.set_header("Content-Type", "application/json; charset=UTF-8")
        except:
            self.set_status(500)
        finally:
            self.finish()
Exemplo n.º 6
0
    def setup(self):
        self.today = datetime.datetime.today()
        self.today_label = tk.Label(self, text="\n" + format_date(self.today),
                                    font=(TODAY_LABEL_CONFIG["font_family"],
                                          TODAY_LABEL_CONFIG["font_size"],
                                          TODAY_LABEL_CONFIG["font_weight"],
                                          TODAY_LABEL_CONFIG["underline"]))
        self.today_label.pack()

        if self.language == "Chinese":
            quote = self.daily_quote["content"] + "\n\n" + self.daily_quote["translation"]
        else:
            quote = self.daily_quote["content"]

        self.quote_label = tk.Label(self, text=quote,
                                    justify=QUOTE_LABEL_CONFIG["justify"],
                                    wraplength=QUOTE_LABEL_CONFIG["wraplength"])
        self.quote_label.config(font=(QUOTE_LABEL_CONFIG["font_family"],
                                      QUOTE_LABEL_CONFIG["font_size"],
                                      QUOTE_LABEL_CONFIG["font_weight"]))
        self.quote_label.pack(padx=QUOTE_LABEL_CONFIG["padx"],
                              pady=QUOTE_LABEL_CONFIG["pady"])
Exemplo n.º 7
0
def getWordTrend():
    word = request.args.get("word").lower()
    print("New Word: {0}".format(word))
    worddb = open(wordquerydb, "r")
    print("Word data opened for reading")
    wordcloud_data = json.load(worddb)
    worddb.close()
    print("Word data closed for reading")
    date_str = format_date(4)
    word_date = {}
    word_date["word"] = word
    word_date["frequency"] = []
    for key in wordcloud_data.keys():
        old_date_arr = [int(it) for it in key.split("-")]
        new_date_arr = [int(it) for it in date_str.split("-")]
        if calculate_diff_hour(old_date_arr, new_date_arr) <= 24:
            for ele in wordcloud_data[key]:
                if ele["word"] == word:
                    word_date["frequency"].append({
                        "date": old_date_arr,
                        "value": ele["frequency"]
                    })
    print("Send: {0}", json.dumps(word_date))
    return json.dumps(word_date)
Exemplo n.º 8
0
 def start_str(self) -> str:
     """Returns a formatted string of the start date"""
     return format_date(self.start(), all_day=self.all_day()) or "Today"