Aditya Patkar commited on
Commit
4d6b011
·
1 Parent(s): abd144f

Added all code

Browse files
Files changed (2) hide show
  1. app.py +97 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime as dt
2
+ import pandas as pd
3
+
4
+ import streamlit as st
5
+ from peopledatalabs import PDLPY as pdl
6
+
7
+
8
+ def setup():
9
+ """
10
+ Streamlit related setup. This has to be run for each page.
11
+ """
12
+ hide_streamlit_style = """
13
+
14
+ <style>
15
+ #MainMenu {visibility: hidden;}
16
+ footer {visibility: hidden;}
17
+ </style>
18
+ """
19
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
20
+
21
+ def main():
22
+ '''
23
+ Main function of the app.
24
+ '''
25
+ setup()
26
+ st.title('People Data Labs Query Tool')
27
+
28
+ st.subheader('Search for a Person or Company')
29
+
30
+ st.write('''
31
+ This tool allows you to search for a person or company using the People Data Labs API. \n
32
+ *Guidelines*: \n
33
+ - API Key: Your API key from People Data Labs \n
34
+ - Type: Person or Company \n
35
+ - SQL Query: The SQL query you want to run. Find it on the dashboard \n
36
+ - Dataset: The dataset you want to search in. Leave blank for all \n
37
+ - Size: The number of results you want to return \n
38
+ - Pretty Print: Whether you want the results to be pretty printed. Default is False \n \n\n
39
+ ''')
40
+
41
+ #horizontal line
42
+ st.markdown('<hr>', unsafe_allow_html=True)
43
+ st.markdown('<br>', unsafe_allow_html=True)
44
+
45
+ st.subheader('Search')
46
+ form = st.form(key='my_form')
47
+ api_key = form.text_input(label='API Key')
48
+ type = form.selectbox(label='Type', options=['Person', 'Company'])
49
+ sql_query = form.text_area(label='SQL Query')
50
+ sql_query = sql_query.strip('"')
51
+ dataset = form.text_input(label='Dataset')
52
+ if dataset is None or dataset.strip() == '':
53
+ dataset = 'all'
54
+ size = form.number_input(label='Size', min_value=1, max_value=1000, value=10)
55
+ pretty = form.checkbox(label='Pretty Print')
56
+ submit_button = form.form_submit_button(label='Submit')
57
+
58
+ if submit_button:
59
+ PARAMS = {'sql': sql_query, 'dataset': dataset, 'size': size, 'pretty': pretty}
60
+
61
+ client = pdl(api_key=api_key)
62
+
63
+ if type == 'Person':
64
+ response = client.person.search(**PARAMS).json()
65
+
66
+ elif type == 'Company':
67
+ response = client.company.search(**PARAMS).json()
68
+
69
+ if response["status"] == 200:
70
+ st.success(f"Found {response['total']} records for this search.")
71
+ data = response['data']
72
+
73
+ #convert json to csv. Json is list of dicts
74
+ df = pd.DataFrame(data)
75
+ csv = df.to_csv(index=False)
76
+
77
+ #show data
78
+ st.markdown('<hr>', unsafe_allow_html=True)
79
+ st.markdown('<br>', unsafe_allow_html=True)
80
+ st.subheader('Data')
81
+ st.download_button(label='Download CSV', data=csv, file_name=f'{type}-data-{dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}.csv')
82
+ st.dataframe(df)
83
+ else:
84
+ st.error('Error retrieving data!')
85
+ st.error(f"Error: {response}")
86
+
87
+ if __name__ == '__main__':
88
+ main()
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas==2.0.3
2
+ peopledatalabs==1.1.9
3
+ streamlit==1.24.1