-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitemsEntryScript.py
More file actions
54 lines (45 loc) · 1.53 KB
/
Copy pathitemsEntryScript.py
File metadata and controls
54 lines (45 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import mysql.connector
import pandas as pd
from random import randint
# db = mysql.connector.connect(
# host="sql6.freesqldatabase.com",
# user="sql6510904",
# password="HE7SwbFPZT"
# )
db = mysql.connector.connect(
host="localhost",
user="admin",
password="admin"
)
cur = db.cursor()
# cur.execute("USE sql6510904")
cur.execute("USE cbe_stocks")
xl_file = pd.ExcelFile('file.xlsx')
dfs = {sheet_name: xl_file.parse(sheet_name)
for sheet_name in xl_file.sheet_names}
# categories entry
for i in dfs['Articles'].CATEGORY.unique():
cur.execute("INSERT INTO categories (Name) VALUES (%s)", (i,))
db.commit()
# items entry
cat = dfs['Articles'].CATEGORY
items = dfs['Articles'].ITEMS
catID = {'STATIONARY ITEMS': 1, 'CLEANING MATERIALS': 2,
"ELECTRONIC ITEMS": 3, "ELECTRICAL ITEMS": 4, "FORMS": 5}
for i in range(len(cat)):
k = items[i].replace("'", "\\'").replace('"', '\\"')
# s = f"INSERT INTO items (CategoryID, Name, Quantity) VALUES({catID[cat[i]]}, '{k}', {randint(100,1000)})"
s = f"INSERT INTO items (CategoryID, Name, Quantity) VALUES({catID[cat[i]]}, '{k}', 0)"
cur.execute(s)
db.commit()
# stations entry
name = dfs['Station Details']['Name of the PS/ Unit']
for i in name:
cur.execute("INSERT INTO stations (Name) VALUES (%s)", (i,))
db.commit()
schemes = ["-","MPF - Modernization of Police Force",
"DF - Discretionary Funds", "Nirbhaya Funds"]
for i in schemes:
cur.execute("INSERT INTO schemes (Name) VALUES (%s)", (i,))
db.commit()
db.commit()