|
@@ -0,0 +1,71 @@
|
|
|
+import os
|
|
|
+from datetime import datetime
|
|
|
+import requests
|
|
|
+from google.analytics.data_v1beta import BetaAnalyticsDataClient
|
|
|
+from google.analytics.data_v1beta.types import (
|
|
|
+ DateRange,
|
|
|
+ Dimension,
|
|
|
+ Metric,
|
|
|
+ MetricType,
|
|
|
+ RunReportRequest,
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+property_id = [
|
|
|
+ ["290055766","Simpleprotein - GA4",{
|
|
|
+ "Authorization": "Bearer " + "DC7eiXkGoKzXcuCTuqCGmuNnDC15D3iv6E7tu5BAsUZ",
|
|
|
+ "Content-Type": "application/x-www-form-urlencoded"},"C:\/Users\/s1301\/Downloads\/corded-velocity-301807-879b27e60620.json"],
|
|
|
+ ["349445560","www.lisinbeauty.com",{"Authorization": "Bearer " + "4RO6ZOS4b7TkuqknajBPibTnOYnumHfwJvRzdZ3Bmq6",
|
|
|
+ "Content-Type": "application/x-www-form-urlencoded"},"C:\/Users\/s1301\/Downloads\/corded-velocity-301807-c1a87c5dfc8d.json"]]
|
|
|
+
|
|
|
+pv_target = 0
|
|
|
+
|
|
|
+show_target = 0
|
|
|
+
|
|
|
+
|
|
|
+send = 1
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def send_msg(msg,lineid):
|
|
|
+ current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
|
+ params = {"message": "Time: " + current_time + "\n" + msg}
|
|
|
+
|
|
|
+
|
|
|
+def run_report():
|
|
|
+
|
|
|
+ total = 0
|
|
|
+ message = ""
|
|
|
+
|
|
|
+ for p in property_id:
|
|
|
+ os.environ['GOOGLE_APPLICATION_CREDENTIALS']=p[3]
|
|
|
+ client = BetaAnalyticsDataClient()
|
|
|
+ request = RunReportRequest(
|
|
|
+ property=f"properties/{p[0]}",
|
|
|
+ metrics=[Metric(name="screenPageViews")],
|
|
|
+ date_ranges=[DateRange(start_date="2023-02-19", end_date="2023-02-19")],
|
|
|
+ )
|
|
|
+ response = client.run_report(request)
|
|
|
+
|
|
|
+ for rowIdx, row in enumerate(response.rows):
|
|
|
+ for i, metric_value in enumerate(row.metric_values):
|
|
|
+ metric_name = response.metric_headers[i].name
|
|
|
+ viewcount = metric_value.value
|
|
|
+ message = message + (f"{p[1]} / {metric_name}: {viewcount}\n")
|
|
|
+ total = total + int(viewcount)
|
|
|
+ message = message + (f"Total views: {total}\n")
|
|
|
+ if show_target == 1:
|
|
|
+ if total >= pv_target:
|
|
|
+ message = message + ("Target reached\n")
|
|
|
+ else:
|
|
|
+ message = message + ("Target not reached\n")
|
|
|
+ print(message)
|
|
|
+ send_msg(message,p[2])
|
|
|
+
|
|
|
+run_report()
|