-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure_mssql.py
53 lines (39 loc) · 1.42 KB
/
azure_mssql.py
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
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 12 08:58:30 2017
@author: picturio
"""
import os
import pandas as pd
import pymssql
import json
user='SzMike'
base_folder = os.path.curdir
image_dir=r'C:\Users\SzMike\OneDrive\WISH'
#image_dir=r'e:\WISH\data\classification'
image_list_file=os.path.join(base_folder,'input','image_list.json')
image_category_file=os.path.join(base_folder,'input','image_category.json')
server = "bzte7q7g05.database.windows.net"
user = "ImageSearchUser@bzte7q7g05"
pswd = "IS_D152AE3C-EF13-466F-8D1D-5C612645C3F5"
db_name = "ImageSearchProd"
conn = pymssql.connect(server, user, pswd, db_name)
query='SELECT category, blobUrl from dbo.Products'
prod_db = pd.read_sql(query, con=conn)
image_label={}
image_list_indir=[]
for row in prod_db.iterrows():
image_file=image_dir+row[1]['blobUrl']
if os.path.isfile(image_file):
image_list_indir.append(image_file)
image_label[image_file]=row[1]['category']
with open(image_list_file, 'w') as imagelistfile:
json.dump(image_list_indir,imagelistfile)
with open(image_category_file, 'w', encoding='utf-16') as imagecatfile:
json.dump(image_label,imagecatfile, ensure_ascii=False)
test_image_dir=r'C:\Users\picturio\OneDrive\WISH\TestImages_praktiker'
categories=prod_db['category'].unique()
for c in categories:
newpath=os.path.join(test_image_dir,c)
if not os.path.exists(newpath):
os.makedirs(newpath)