Discover how to streamline Magento version detection with Python. Learn to effortlessly retrieve Magento versions from multiple URLs and update CSV files, simplifying the management of Magento-powered websites.
import pandas as pd
import requests
import re
def get_magento_version(url):
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for HTTP errors
decoded_content = response.content.decode('utf-8')
magento_match = re.search(r'Magento.*', decoded_content)
if magento_match:
return magento_match.group()
else:
return ''
except requests.RequestException as e:
return ''
# Load CSV into DataFrame
df = pd.read_csv('datacsv2.csv')
# Apply get_magento_version function to each URL and create a new column with the result
df['Magento Version'] = df['data'].apply(get_magento_version)
# Save DataFrame to new CSV file
df.to_csv('datacsv5.csv', index=False)
new updated version
import pandas as pd
import requests
import re
def get_magento_version(url):
try:
full_url = url + '/magento_version'
response = requests.get(full_url)
response.raise_for_status() # Raise an exception for HTTP errors
decoded_content = response.content.decode('utf-8')
magento_match = re.search(r'Magento.*', decoded_content)
if magento_match:
print(f"Found Magento version for row {row_num}: {url}: {magento_match.group()}")
return magento_match.group()
else:
print(f"No Magento version found for row {row_num}: {url}")
return ''
except requests.RequestException as e:
print(f"Request failed for row {row_num}: {url}: {e}")
return ''
# Load CSV into DataFrame
df = pd.read_csv('data.csv')
df['data'] = df['data'].str.replace('\\', '/')
# Apply get_magento_version function to each URL and create a new column with the result
df['Magento Version'] = ''
for row_num, row in df.iterrows():
df.at[row_num, 'Magento Version'] = get_magento_version(row['data'])
# Save DataFrame to new CSV file
df.to_csv('result.csv', index=False)