Skip to content

Instantly share code, notes, and snippets.

@AjayKrP
Last active March 5, 2021 05:11
Show Gist options
  • Save AjayKrP/5cb17f7d5dc1f3090d221abf9e032eb1 to your computer and use it in GitHub Desktop.
Save AjayKrP/5cb17f7d5dc1f3090d221abf9e032eb1 to your computer and use it in GitHub Desktop.
Upload Larger Table Rates In Magento 2 Using Python
import csv
import mysql.connector
import time
mydb = mysql.connector.connect(
host="your_db_host",
user="db_user",
password="*****",
database="db_name"
)
mycursor = mydb.cursor()
sql = "INSERT INTO shipping_tablerate (dest_country_id, dest_region_id, dest_zip, condition_value, price, condition_name) VALUES (%s, %s, %s, %s, %s, 'package_weight')"
with open('1.csv', 'r') as file:
reader = csv.reader(file, delimiter = ',')
isFirst = 0
for row in reader:
"""
website_id
dest_country_id
dest_region_id
dest_zip
condition_value
price
"""
print(row)
if isFirst >= 1:
try:
mycursor.execute(sql, row)
except:
print("exception")
isFirst += 1
#time.sleep(0.01)
mydb.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment