Esempio n. 1
0
def question():
    ques = input("Question: ")
    app_id = "P3Y74H-APQLLLRWTG"
    client = wolframalpha.Client(app_id)
    res = client.query(ques)
    answer = next(res.results).text
    print(answer)
    welcomeuser()
Esempio n. 2
0
def remove_if_not_complete(content_owner, table, _date):
    try:
        query_job = client.query('''DELETE FROM `pops-204909.''' +
                                 content_owner + "." + table + "`" +
                                 " WHERE date='" + _date.replace("-", "") +
                                 "'")
        rows = query_job.result()
    except:
        pass
def remove_if_not_complete_month(content_owner, table, _date):
    try:
        query_job = client.query(
            '''DELETE FROM `pops-204909.''' + content_owner + "." + table +
            "`" + " WHERE PARSE_DATE('%Y%m%d',date) >= PARSE_DATE('%Y%m%d','" +
            _date.replace("-", "") + "')")
        rows = query_job.result()
    except:
        pass
Esempio n. 4
0
    async def ask(self, ctx, *, query):
        res = client.query(query)
        if res['@success'] == 'false':
            strRes = "Couldn't find an answer"
        else:
            strRes = next(res.results).text

        answer = '**' + query + '**' + '\n```' + strRes + '```'
        await self.bot.say(answer)
Esempio n. 5
0
def get_lastest_month_func(content_owner, table):
    query_job = client.query(
        '''SELECT MAX( PARSE_DATE('%Y%m%d',date))  AS `newest_month_BG`
                             FROM `pops-204909.''' + content_owner + "." +
        table + "`")
    rows = query_job.result()
    for i_row in rows:
        _newest_month_BG = i_row.get('newest_month_BG')
        return datetime(int(str(_newest_month_BG).split("-")[0]),
                        int(str(_newest_month_BG).split("-")[1]), 1)
Esempio n. 6
0
    def datetime_to_utc(timedate):
        app_id = 'L3J57Q-TWXW7R75RT'
        client = wolframalpha.Client(app_id)
        res = client.query('timestamp of ' + timedate)

        answer = next(res.results).text
        unix = int(re.sub('\(.*?\)', '', answer))

        utc = pytz.utc
        a_date = datetime.utcfromtimestamp(unix)
        utc_date = utc.localize(a_date).isoformat()
        return utc_date
Esempio n. 7
0
def get_latest_date_func(content_owner, table):
    query_job = client.query(
        '''SELECT MAX( PARSE_DATE('%Y%m%d',date))  AS `lastest_date_BQ`
                             FROM `pops-204909.''' + content_owner + "." +
        table + "`")
    rows = query_job.result()
    for i_row in rows:
        _lastest_date_BQ = i_row.get('lastest_date_BQ')
        try:
            _date = datetime(_lastest_date_BQ.year, _lastest_date_BQ.month,
                             _lastest_date_BQ.day)
            return _date
        except AttributeError:
            pass
Esempio n. 8
0
def check_upload(file_name, content_owner, table, _date):
    data = pd.read_table(file_name, sep=",")
    data = data.replace(np.nan, '', regex=True)
    try:
        query_job = client.query(
            '''SELECT count(*) as `row_number` FROM `pops-204909.''' +
            content_owner + "." + table + "`" + " WHERE date='" +
            _date.replace("-", "") + "'")
        rows = query_job.result()
        for i_row in rows:
            row_number = i_row.get('row_number')
            print("row_number = ", int(row_number), "     ", "len(data)= ",
                  len(data))
            if int(row_number) == len(data):
                os.remove(file_name)
            else:
                remove_if_not_complete(content_owner=content_owner,
                                       table=table,
                                       _date=_date)
    except (ValueError, KeyError) as e:
        print("Could not remove the file!")