async def trends(ctx): await ctx.send(f"enter start year") message_response = await client.wait_for('message') start_year = int(message_response.content) print(start_year) await ctx.send(f"enter end year") message_response = await client.wait_for('message') end_year = int(message_response.content) print(end_year) await ctx.send(f"enter start month from range 1-12") message_response = await client.wait_for('message') start_month = int(message_response.content) print(start_month) await ctx.send(f"enter end month range 1-12 ") message_response = await client.wait_for('message') end_month = int(message_response.content) print(end_month) await ctx.send(f"enter start day range 1 - 30") message_response = await client.wait_for('message') start_day = int(message_response.content) print(start_day) await ctx.send(f"enter end day 1 - 30") message_response = await client.wait_for('message') end_day = int(message_response.content) print(end_day) await ctx.send(f"enter search word") message_response = await client.wait_for('message') search_word = str(message_response.content) print(search_word) await ctx.send(f"enter region") message_response = await client.wait_for('message') region = str(message_response.content) print(region) start = dt.datetime(year=start_year, month=start_month, day=start_day) end = dt.datetime(year=end_year, month=end_month, day=end_day) connection = GoogleConnection() series = SVSeries.univariate(connection=connection, query={ 'key': search_word, 'geo': region }, start=start, end=end, granularity='MONTH') google_data = series.get_data() plt.plot(google_data) plt.savefig("pic.jpeg")
def setUp(self) -> None: self.connection = GoogleConnection(timeout=30)
def setUp(self) -> None: """ sets the connection up. """ self.connection = GoogleConnection(timeout=30)
class GoogleConnectionTest(unittest.TestCase): """ Tests the GoogleConnection. """ def setUp(self) -> None: """ sets the connection up. """ self.connection = GoogleConnection(timeout=30) def test_count(self): """ Simple query count check. """ queries = [{str(i): str(i)} for i in range(10)] self.assertRaises(ValueError, self.connection.get_timeseries, queries) def test_single_short_daily(self): """ Tests a single query for 2 days worldwide. Subtests check the length of the resulting series, the normalization, the start and end date. """ start = datetime.datetime(year=2019, month=9, day=1) end = datetime.datetime(year=2019, month=9, day=2) queries = [{'key': 'apple', 'geo': '', 'range': (start, end)}] result = self.connection.get_timeseries(queries, granularity='DAY') with self.subTest('result_count'): self.assertEqual(len(queries), len(result)) with self.subTest('result_length'): self.assertEqual((end - start).days + 1, len(result[0].index)) with self.subTest('result_normalized'): self.assertEqual(result[0].max(), 100) with self.subTest('result_start'): self.assertEqual(result[0].index.date[0], start.date()) with self.subTest('result_end'): self.assertEqual(result[0].index.date[-1], end.date()) def test_multi_long_daily(self): """ Tests multiple queries for 269 days in geo US and category COMPUTERS_ELECTRONICS. Subtests check the length of the resulting series, the normalization, the start and end date. """ start = datetime.datetime(year=2004, month=1, day=1) end = datetime.datetime(year=2004, month=9, day=26) queries = [{ 'key': 'apple', 'geo': 'US', 'range': (start, end) }, { 'key': 'orange', 'geo': 'US', 'range': (start, end) }, { 'key': 'banana', 'geo': 'US', 'range': (start, end) }, { 'key': 'kiwi', 'geo': 'US', 'range': (start, end) }, { 'key': 'strawberry', 'geo': 'US', 'range': (start, end) }] result = self.connection.get_timeseries(queries, granularity='DAY') with self.subTest('result_count'): self.assertEqual(len(queries), len(result)) with self.subTest('result_length'): for series in result: self.assertEqual((end - start).days + 1, len(series.index)) with self.subTest('result_normalized'): self.assertGreaterEqual( sum([result[i].max() == 100 for i in range(len(result))]), 1) with self.subTest('result_start'): for series in result: self.assertEqual(series.index.date[0], start.date()) with self.subTest('result_start'): for series in result: self.assertEqual(series.index.date[0], start.date()) def test_invalid_dates(self): """ Tests case start > end. """ start = datetime.datetime(year=2019, month=9, day=10) end = datetime.datetime(year=2019, month=9, day=1) queries = [{'key': 'apple', 'geo': '', 'range': (start, end)}] self.assertRaises(requests.exceptions.RequestException, self.connection.get_timeseries, queries) def test_invalid_geo(self): """ Tests invalid geo. """ start = datetime.datetime(year=2019, month=9, day=10) end = datetime.datetime(year=2019, month=9, day=1) queries = [{'key': 'apple', 'geo': 'FAIL', 'range': (start, end)}] self.assertRaises(requests.exceptions.RequestException, self.connection.get_timeseries, queries)