-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a5e5f75
Showing
7 changed files
with
12,145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
# dbMagic | ||
dbMagic is a simple python script which allows you to edit .sql file with out the need of MySQL. | ||
|
||
## Getting Started | ||
To run this script you will need | ||
- Python3 | ||
|
||
### Prerequisites | ||
|
||
Installations | ||
- python3 | ||
- tqdm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#!/usr/bin/env python3 | ||
import sys | ||
import glob | ||
import argparse | ||
import threading | ||
from tqdm import tqdm | ||
|
||
class DBMagic: | ||
def __init__(self, filename, changeFilename, changeToFilename, stud_id): | ||
self.file = None | ||
self.modFile = None | ||
self.stud_id = str(stud_id) | ||
self.changeList = [] | ||
self.changeToList = [] | ||
self.filename = str(filename) | ||
self.changeFilename = str(changeFilename) | ||
self.changeToFilename = str(changeToFilename) | ||
self.modFilename = self.filename + ".mod" | ||
self.line_mod = 0 | ||
self.filename_count = 0 | ||
|
||
def fileOpen(self): | ||
if glob.glob(self.filename): | ||
self.filename_count = sum(1 for line in open(self.filename)) # get count | ||
self.file = open(self.filename, 'r') | ||
else: | ||
print("[-] The filename %s is not found!" % self.filename) | ||
exit(1) | ||
|
||
def fileClose(self, obj): | ||
if obj is not None: | ||
obj.close() | ||
else: | ||
print("[!] There is nothing to close! - file") | ||
|
||
def createModFile(self): | ||
if glob.glob(self.modFilename): | ||
print("[!] The file %s already exists!" % self.modFilename) | ||
exit(1) | ||
self.modFile = open(self.modFilename, 'w') | ||
|
||
|
||
def loadChangeFile(self): | ||
if glob.glob(self.changeFilename): | ||
with open(self.changeFilename, 'r') as f: | ||
for l in f: | ||
self.changeList.append(l.replace('\n', '')) | ||
f.close() # close the file | ||
else: | ||
print("[-] The file %s is not found!" % self.changeFilename) | ||
exit(1) | ||
|
||
def loadChangeToFile(self): | ||
if glob.glob(self.changeToFilename): | ||
with open(self.changeToFilename, 'r') as f: | ||
for l in f: | ||
self.changeToList.append(l) | ||
f.close() # close the file | ||
else: | ||
print("[-] The file %s is not found!" % self.changeToFilename) | ||
exit(1) | ||
|
||
def displayChanges(self): | ||
print("\n[*] Total changes: %d\n" % self.line_mod) | ||
|
||
@staticmethod | ||
def striper(s): | ||
return s.replace(' ', '').replace('\n', '') | ||
|
||
def extractFields(self, s): | ||
print("[+] Creating extract.lst...") | ||
g = open("extract.lst", "w") | ||
pb = tqdm(total=self.filename_count) | ||
self.fileOpen() | ||
|
||
with self.file as f: | ||
for line in f: | ||
pb.update(1) # update the bar everytime we hit a line | ||
if s in line: | ||
g.write(line) | ||
else: pass | ||
f.close() # close the file | ||
pb.close() # close the progress bar... | ||
g.close() | ||
print("[*] Done extracting...") | ||
|
||
def readFile(self): | ||
pb = tqdm(total=self.filename_count) | ||
with self.modFile as wable: | ||
with self.file as f: | ||
for line in f: | ||
pb.update(1) # update the bar everytime we hit a line | ||
if self.stud_id in line: | ||
for chg in self.changeList: | ||
if self.striper(chg) == self.striper(line): | ||
wable.write(self.changeToList[0]) | ||
self.changeToList.pop(0) # remove the first index | ||
self.line_mod += 1 | ||
else: pass | ||
else: | ||
wable.write(line) | ||
f.close() # close the file | ||
wable.close() # close wable | ||
pb.close() # close the progress bar... | ||
|
||
def start(self): | ||
print("[*] Starting DBMagic...\n") | ||
self.fileOpen() | ||
self.createModFile() | ||
self.loadChangeFile() | ||
self.loadChangeToFile() | ||
self.readFile() | ||
self.displayChanges() | ||
print("[*] Done.") | ||
|
||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument('-s', '--sql', help='to set the sql data', required=True) | ||
parser.add_argument('-c', '--changelist', help='to set the change list') | ||
parser.add_argument('-t', '--tochangelist', help='to set the to-change list') | ||
parser.add_argument('-m', '--match', help='to match the list of data with this string', required=True) | ||
parser.add_argument('-e', '--extract', help='this option is for extracting line with -m string', action='store_true') | ||
|
||
args = parser.parse_args() | ||
|
||
sql = args.sql | ||
changelist = args.changelist | ||
tochangelist = args.tochangelist | ||
match = args.match | ||
extract = args.extract | ||
|
||
if extract: | ||
DBMagic(filename=sql, changeFilename=changelist, changeToFilename=tochangelist, stud_id=match).extractFields(match) | ||
else: | ||
DBMagic(filename=sql, changeFilename=changelist, changeToFilename=tochangelist, stud_id=match).start() | ||
|
||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tqdm==4.39.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
('S12_3380','1968 Dodge Charger','Classic Cars','1:12','Welly Diecast Productions','1:12 scale model of a 1968 Dodge Charger. Hood, doors and trunk all open to reveal highly detailed interior features. Steering wheel actually turns the front wheels. Color black',9123,'75.16','117.44'), | ||
('S18_1342','1937 Lincoln Berline','Vintage Cars','1:18','Motor City Art Classics','Features opening engine cover, doors, trunk, and fuel filler cap. Color black',8693,'60.62','102.74'), | ||
('S18_2795','1928 Mercedes-Benz SSK','Vintage Cars','1:18','Gearbox Collectibles','This 1:18 replica features grille-mounted chrome horn, lift-up louvered hood, fold-down rumble seat, working steering system, chrome-covered spare, opening doors, detailed and wired engine. Color black.',548,'72.56','168.75'), | ||
('S18_3856','1941 Chevrolet Special Deluxe Cabriolet','Vintage Cars','1:18','Exoto Designs','Features opening hood, opening doors, opening trunk, wide white wall tires, front door arm rests, working steering system, leather upholstery. Color black.',2378,'64.58','105.87'), | ||
('S18_4409','1932 Alfa Romeo 8C2300 Spider Sport','Vintage Cars','1:18','Exoto Designs','This 1:18 scale precision die cast replica features the 6 front headlights of the original, plus a detailed version of the 142 horsepower straight 8 engine, dual spares and their famous comprehensive dashboard. Color black.',6553,'43.26','92.03'), | ||
('S24_2022','1938 Cadillac V-16 Presidential Limousine','Vintage Cars','1:24','Classic Metal Creations','This 1:24 scale precision die cast replica of the 1938 Cadillac V-16 Presidential Limousine has all the details of the original, from the flags on the front to an opening back seat compartment complete with telephone and rifle. Features factory baked-enamel black finish, hood goddess ornament, working jump seats.',2847,'20.61','44.80'), | ||
('S24_3816','1940 Ford Delivery Sedan','Vintage Cars','1:24','Carousel DieCast Legends','Chrome Trim, Chrome Grille, Opening Hood, Opening Doors, Opening Trunk, Detailed Engine, Working Steering System. Color black.',6621,'48.64','83.86'), | ||
('S24_3969','1936 Mercedes Benz 500k Roadster','Vintage Cars','1:24','Red Start Diecast','This model features grille-mounted chrome horn, lift-up louvered hood, fold-down rumble seat, working steering system and rubber wheels. Color black.',2081,'21.75','41.03'), | ||
('S700_3505','The Titanic','Ships','1:700','Carousel DieCast Legends','Completed model measures 19 1/2 inches long, 9 inches high, 3inches wide and is in barn red/black. All wood and metal.',1956,'51.09','100.17'), |
Oops, something went wrong.