Skip to content

Instantly share code, notes, and snippets.

@CharlyWargnier
Created April 20, 2020 17:40
Show Gist options
  • Save CharlyWargnier/2cce4d44ef2164335961a190e97799e8 to your computer and use it in GitHub Desktop.
Save CharlyWargnier/2cce4d44ef2164335961a190e97799e8 to your computer and use it in GitHub Desktop.
import streamlit as st
import pandas as pd
import pandas as pd
import requests
import base64
import os
st.markdown('## **Bulk HTTP Status Code Checker**')
st.markdown('*Made with* :heart: *with [Streamlit](https://www.streamlit.io/)*')
### Load URLs by file uploader
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
if uploaded_file is not None:
data = pd.read_csv(uploaded_file)
st.write(data)
#st.header("Show imported data")
if st.button("Show imported data"):
st.table(data)
#st.dataframe(df.head())
data['code'] = data.url.apply(lambda url: requests.get(url, allow_redirects=False).status_code)
data['code'] = data['code'].astype(str)
data['code_Class'] = pd.np.where(data.code.str.contains("^1.*"), 'Info (1XX)',
pd.np.where(data.code.str.contains("^2.*"), 'Success (2XX)',
pd.np.where(data.code.str.contains("^3.*"), 'Redirects (3XX)',
pd.np.where(data.code.str.contains("^4.*"), 'Client errors (4XX)', 'Server errors (5XX)'))))
############# Progress Bar #############
import time
#Add a placeholder
latest_iteration = st.empty()
bar = st.progress(0)
for i in range(100):
# Update the progress bar with each iteration.
latest_iteration.text(f'Progress {i+1}')
bar.progress(i + 1)
time.sleep(0.1)
#'...and now we\'re done!'
st.sidebar.header("Status Codes to export")
myNewList = []
#df = get_data()
code_blocked = st.sidebar.checkbox("Blocked/not crawled (0)", value=True)
code_ok = st.sidebar.checkbox("Success (2XX)")
code_redirect = st.sidebar.checkbox("Redirects (3XX)", value=True)
code_not_found = st.sidebar.checkbox("Client errors (4XX)", value=True)
code_server = st.sidebar.checkbox("Server errors (5XX)")
FilteredDF = data[(data['code_Class'].isin(myNewList))]
# CSV export
csv = FilteredDF.to_csv(index=False)
b64 = base64.b64encode(csv.encode()).decode() # some strings <-> bytes conversions necessary here
href = f'<a href="data:file/csv;base64,{b64}">Download CSV File</a> (right-click and save as &lt;name&gt;.csv)'
st.markdown(href, unsafe_allow_html=True)
st.table(data)
#############
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment