Ronio Jerico Roque commited on
Commit
6670e8d
·
1 Parent(s): 792e40c

Add helper modules for session initialization, telemetry collection, and file uploads

Browse files
helper/desc.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Analysts = {
2
+ "Analyst 1": "SEO Off Page Optimization Analyst",
3
+ "Analyst 2": "SEO On Page Optimization Analyst",
4
+ "Analyst 3": "SEO Analyst",
5
+ "Analyst 4": "Social Media Analyst",
6
+ "Analyst 5": "Lead List Analyst",
7
+ "Analyst 6": "AI Content Curation and Creation Assistant",
8
+ "Analyst 7": "SEO On Page Optimization Analyst",
9
+ "Analyst 8": "SEO On Page Optimization Analyst",
10
+ }
11
+ Data_Source = {
12
+ "Analyst_Src 1": "Data Sources - SEMRush",
13
+ "Analyst_Src 2": "Data Source - Screaming Frog",
14
+ "Analyst_Src 3": "Data Sources - SEMRush",
15
+ "Analyst_Src 4": "Data Source -",
16
+ "Analyst_Src 5": "Data Source -",
17
+ "Analyst_Src 6": "Data Source -",
18
+ "Analyst_Src 7": "SEO On Page Optimization Analyst",
19
+ "Analyst_Src 8": "SEO On Page Optimization Analyst",
20
+ }
21
+ Analysts_Description = {
22
+ "Analyst_Desc 1": "Upload Backlink List (PDF)",
23
+ "Analyst_Desc 2": "Upload Files - Crawl (CSV)",
24
+ "Analyst_Desc 3": "Upload Backlinks List (PDF)",
25
+ "Analyst_Desc 4": "Ex. SEO Keywords, Traffic Channels, Backlinks (CSV) ",
26
+ "Analyst_Desc 5": "",
27
+ "Analyst_Desc 6": "",
28
+ "Analyst_Desc 7": "Ex. SEO Keywords, Traffic Channels, Backlinks (CSV) ",
29
+ "Analyst_Desc 8": "Ex. SEO Keywords, Traffic Channels, Backlinks (CSV) ",
30
+ }
helper/initialize_analyze_session.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def initialize_analyze_session():
4
+ if 'analyzing' not in st.session_state:
5
+ st.session_state['analyzing'] = False
6
+ return st.session_state.get('analyzing', False)
7
+
helper/telemetry.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ from datetime import datetime, timedelta, timezone
4
+ from pymongo import MongoClient
5
+ from dotenv import load_dotenv
6
+
7
+ load_dotenv()
8
+
9
+ def collect_telemetry(data):
10
+ """
11
+ Sends JSON data to a remote MongoDB instance.
12
+
13
+ Args:
14
+ data (dict): The JSON data to send.
15
+ """
16
+ mongodb_uri = os.getenv("MONGODB_URI")
17
+ if not mongodb_uri:
18
+ print("Telemetry skipped, no database configured.")
19
+ return
20
+
21
+ try:
22
+ # Get the current UTC time
23
+ utc_now = datetime.now(timezone.utc)
24
+
25
+ # Define the GMT+8 timezone offset
26
+ gmt_plus_8 = timezone(timedelta(hours=8))
27
+
28
+ # Convert the UTC time to GMT+8
29
+ timestamp = utc_now.astimezone(gmt_plus_8).isoformat()
30
+ data['timestamp'] = timestamp
31
+ client = MongoClient(mongodb_uri)
32
+ db = client.get_database() # Use the default database specified in the URI
33
+ collection = db["telemetry"] # Replace "telemetry" with your desired collection name
34
+ collection.insert_one(data)
35
+ print("Data successfully sent to MongoDB.")
36
+ except Exception as e:
37
+ print(f"Error sending data to MongoDB: {e}")
38
+ finally:
39
+ client.close()
helper/upload_File.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import pymupdf
4
+ from helper.button_behaviour import hide_button, unhide_button
5
+
6
+ class uploadFile:
7
+ def __init__(self):
8
+ self.file_dict = {}
9
+ self.file_gt = {}
10
+
11
+ def multiple_upload_file(self, uploaded_files):
12
+ for _ in range(len(self.file_dict)):
13
+ self.file_dict.popitem()
14
+
15
+ for uploaded_file in uploaded_files:
16
+ if uploaded_file.type == "application/pdf":
17
+ try:
18
+ with pymupdf.open(stream=uploaded_file.read(), filetype="pdf") as doc:
19
+ text = chr(12).join([page.get_text() for page in doc])
20
+ self.file_dict[uploaded_file.name] = {'type': 'pdf', 'content': text}
21
+ except Exception:
22
+ pass
23
+ elif uploaded_file.type == "text/csv":
24
+ try:
25
+ df = pd.read_csv(uploaded_file)
26
+ self.file_dict[uploaded_file.name] = {'type': 'csv', 'content': df}
27
+ except Exception:
28
+ pass
29
+
30
+ st.session_state['uploaded_files'] = self.file_dict
31
+
32
+ def upload_file_seo(self, uploaded_files):
33
+ for _ in range(len(self.file_dict)):
34
+ self.file_dict.popitem()
35
+
36
+ for uploaded_file in uploaded_files:
37
+ if uploaded_file.type == "application/pdf":
38
+ try:
39
+ with pymupdf.open(stream=uploaded_file.read(), filetype="pdf") as doc:
40
+ text = chr(12).join([page.get_text() for page in doc])
41
+ self.file_dict[uploaded_file.name] = {'type': 'pdf', 'content': text}
42
+ except Exception:
43
+ pass
44
+ elif uploaded_file.type == "text/csv":
45
+ try:
46
+ content = uploaded_file.read().decode("utf-8")
47
+ self.file_dict[uploaded_file.name] = {'type': 'csv', 'content': content}
48
+ except Exception:
49
+ pass
50
+
51
+ st.session_state['uploaded_files'] = self.file_dict
52
+
53
+ def upload_gt(self, gtmetrix):
54
+ for _ in range(len(self.file_gt)):
55
+ self.file_gt.popitem()
56
+
57
+ for gtmetrixs in gtmetrix:
58
+ if gtmetrixs.type == "application/pdf":
59
+ try:
60
+ with pymupdf.open(stream=gtmetrixs.read(), filetype="pdf") as doc:
61
+ text = chr(12).join([page.get_text() for page in doc])
62
+ self.file_gt[gtmetrixs.name] = {'type': 'pdf', 'content': text}
63
+ except Exception:
64
+ pass
65
+ elif gtmetrixs.type == "text/csv":
66
+ try:
67
+ content = gtmetrixs.read().decode("utf-8")
68
+ self.file_dict[gtmetrixs.name] = {'type': 'csv', 'content': content}
69
+ except Exception:
70
+ pass
71
+ st.session_state['uploaded_gt'] = self.file_gt
72
+
73
+ if __name__ == "__main__":
74
+ app = uploadFile()
75
+ st.set_page_config(layout="wide")
76
+
77
+
78
+