joshuadunlop commited on
Commit
83fcbe6
·
verified ·
1 Parent(s): 514f0d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -3
app.py CHANGED
@@ -84,6 +84,10 @@ def process_pasted_data(data):
84
  reader = csv.reader(data_io, delimiter='\n', quotechar='"')
85
  return [row[0] for row in reader]
86
 
 
 
 
 
87
  # Streamlit layout
88
  st.sidebar.title("DataForSEO API Parameters")
89
  api_login = st.sidebar.text_input("API Login", value="[email protected]")
@@ -161,11 +165,39 @@ if add_row:
161
  if reset:
162
  st.session_state.clear()
163
 
164
- # Main app layout
165
  row_count = st.session_state.get("row_count", 1)
 
 
166
  for i in range(row_count):
167
- target_url_key = f"target_url_{i}"
168
- target_url = st.text_input(f"Enter the target URL {i + 1}", key=target_url_key)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
  # Generate and reset button logic
171
  generate_button = st.sidebar.button("Generate All")
 
84
  reader = csv.reader(data_io, delimiter='\n', quotechar='"')
85
  return [row[0] for row in reader]
86
 
87
+ def concatenate_dfs(dfs):
88
+ combined_df = pd.concat(dfs, ignore_index=True)
89
+ return combined_df.to_csv(index=False).encode('utf-8')
90
+
91
  # Streamlit layout
92
  st.sidebar.title("DataForSEO API Parameters")
93
  api_login = st.sidebar.text_input("API Login", value="[email protected]")
 
165
  if reset:
166
  st.session_state.clear()
167
 
168
+ # Main app layout with columns
169
  row_count = st.session_state.get("row_count", 1)
170
+ dfs = [] # List to store individual DataFrames
171
+
172
  for i in range(row_count):
173
+ col1, col2 = st.columns(2)
174
+ with col1:
175
+ target_url_key = f"target_url_{i}"
176
+ target_url = st.text_input(f"Enter the target URL {i + 1}", key=target_url_key)
177
+
178
+ # Generate and download button logic per row
179
+ df_key = f"df_{i}"
180
+ df = st.session_state.get(df_key)
181
+ if df is not None:
182
+ dfs.append(df) # Append DataFrame to the list for later use
183
+ csv = convert_df_to_csv(df)
184
+ with col2:
185
+ st.download_button(
186
+ label=f"Download data as CSV for URL {i + 1}",
187
+ data=csv,
188
+ file_name=f'backlinks_{i + 1}.csv',
189
+ mime='text/csv',
190
+ )
191
+
192
+ # Combined CSV download logic
193
+ if st.sidebar.button("Download Combined CSV") and dfs:
194
+ combined_csv = concatenate_dfs(dfs)
195
+ st.sidebar.download_button(
196
+ label="Download Combined Data as CSV",
197
+ data=combined_csv,
198
+ file_name='combined_backlinks.csv',
199
+ mime='text/csv',
200
+ )
201
 
202
  # Generate and reset button logic
203
  generate_button = st.sidebar.button("Generate All")