Best Python code snippet using tempest_python
main.py
Source:main.py
1from flask import Flask, render_template, request, abort, url_for, redirect, flash2import json3import numpy4import os5import time6from pymongo import MongoClient7client = MongoClient('localhost', 27017)8Merger_DB = client.Merger_DB9app = Flask(__name__)10app.config['SECRET_KEY'] = '12091988BernardoProvencanoToto'11@app.route('/', methods=['GET', 'POST'])12def main_page():13 return render_template('main_page.html')14@app.route('/beer_grouping_prove')15def beer_grouping_prove():16 return render_template('beer_grouping_prove.html')17@app.route('/champagne_grouping_prove')18def champagne_grouping_prove():19 return render_template('champagne_grouping_prove.html')20@app.route('/cognac_grouping_prove')21def cognac_grouping_prove():22 return render_template('cognac_grouping_prove.html')23@app.route('/vodka_grouping_prove')24def vodka_grouping_prove():25 return render_template('vodka_grouping_prove.html')26@app.route('/whiskey_grouping_prove')27def whiskey_grouping_prove():28 return render_template('whiskey_grouping_prove.html')29# testing beer finished30@app.route('/finished_beer', methods=['GET', 'POST'])31def finished_beer():32 # Merger_DB['Ðиво'].delete_many({})33 # for i in read_file('beer.json'):34 # Merger_DB['Ðиво'].update({'_id': i['_id']}, {'$set': i}, upsert=True)35 #36 # for i in read_file('productData.json'):37 # Merger_DB['productData'].update({'_id': i['id']}, {'$set': i}, upsert=True)38 show_group = None39 group_titles = None40 beer = list(Merger_DB['Ðиво'].find())41 merged_beer = list(Merger_DB['productData'].find({'section': 'Ðиво'}))42 productData_links = [i['links'] for i in merged_beer]43 productData_groups = [i for i in merged_beer]44 if productData_links:45 show_group = productData_links[0]46 show_group = [[i for i in beer if i['link'] in show_group]]47 group_titles = productData_groups[0]48 if 'search' in request.form:49 group_ind = int(request.form['search']) - 150 if group_ind > len(merged_beer):51 flash('У Ð²Ð°Ñ Ð½ÐµÑ ÑÑолÑко гÑÑпп')52 return redirect('/finished_beer')53 show_group = productData_links[group_ind]54 show_group = [[i for i in beer if i['link'] in show_group]]55 group_titles = productData_groups[group_ind]56 if 'next' in request.form:57 for i in productData_groups:58 if i['id'] == request.form['next']:59 ind = productData_groups.index(i)60 if ind != len(productData_groups) - 1:61 show_group = productData_links[ind + 1]62 show_group = [[k for k in beer if k['link'] in show_group]]63 group_titles = productData_groups[ind + 1]64 break65 else:66 show_group = productData_links[-1]67 show_group = [[k for k in beer if k['link'] in show_group]]68 group_titles = productData_groups[-1]69 if 'previous' in request.form:70 for i in productData_groups:71 if i['id'] == request.form['previous']:72 ind = productData_groups.index(i)73 if ind != 0:74 show_group = productData_links[ind - 1]75 show_group = [[k for k in beer if k['link'] in show_group]]76 group_titles = productData_groups[ind - 1]77 break78 else:79 show_group = productData_links[0]80 show_group = [[k for k in beer if k['link'] in show_group]]81 group_titles = productData_groups[0]82 if 'delete_from_finished' in request.form:83 delete_id = request.form['delete_from_finished']84 Merger_DB['productData'].delete_one({'_id': delete_id})85 product_with_id = list(Merger_DB['Ðиво'].find({'product_id': {'$exists': True}}))86 need_to_delete_list = [i for i in product_with_id if i['product_id'] == delete_id]87 for i in need_to_delete_list:88 Merger_DB['Ðиво'].update({'_id': i['_id']}, {'$unset': {'in_productData': 1}},89 upsert=True)90 # Saving data to files91 beer = list(Merger_DB['Ðиво'].find())92 productData_file = list(Merger_DB['productData'].find())93 write_file('productData.json', productData_file)94 write_file('beer.json', beer)95 flash('ÐÑÑппа ÑÑпеÑно оÑпÑавлена на повÑоÑнÑÑ Ð¾Ð±ÑабоÑкÑ')96 return redirect('/finished_beer')97 # ÐÐ¾Ð¼ÐµÑ Ð³ÑÑппÑ98 group_num = 099 if group_titles:100 group_num = productData_groups.index(group_titles) + 1101 # ÑиÑло гоÑовÑÑ
гÑÑпп102 done = Merger_DB['productData'].count_documents({'section': 'Ðиво'})103 return render_template('finished_beer.html', groups=show_group, titles=group_titles, done=done, group_num=group_num)104@app.route('/finished_champagne', methods=['GET', 'POST'])105def finished_champagne():106 # Merger_DB['ШампанÑкое и игÑиÑÑое вино'].delete_many({})107 # for i in read_file('champagne.json'):108 # Merger_DB['ШампанÑкое и игÑиÑÑое вино'].update({'_id': i['_id']}, {'$set': i}, upsert=True)109 #110 # for i in read_file('productData.json'):111 # Merger_DB['productData'].update({'_id': i['id']}, {'$set': i}, upsert=True)112 show_group = None113 group_titles = None114 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())115 merged_champagne = list(Merger_DB['productData'].find({'section': 'ШампанÑкое и игÑиÑÑое вино'}))116 productData_links = [i['links'] for i in merged_champagne]117 productData_groups = [i for i in merged_champagne]118 if productData_links:119 show_group = productData_links[0]120 show_group = [[i for i in champagne if i['link'] in show_group]]121 group_titles = productData_groups[0]122 123 if 'search' in request.form:124 group_ind = int(request.form['search']) - 1125 if group_ind > len(merged_champagne):126 flash('У Ð²Ð°Ñ Ð½ÐµÑ ÑÑолÑко гÑÑпп')127 return redirect('/finished_champagne')128 show_group = productData_links[group_ind]129 show_group = [[i for i in champagne if i['link'] in show_group]]130 group_titles = productData_groups[group_ind]131 if 'next' in request.form:132 for i in productData_groups:133 if i['id'] == request.form['next']:134 ind = productData_groups.index(i)135 if ind != len(productData_groups) - 1:136 show_group = productData_links[ind + 1]137 show_group = [[k for k in champagne if k['link'] in show_group]]138 group_titles = productData_groups[ind + 1]139 break140 else:141 show_group = productData_links[-1]142 show_group = [[k for k in champagne if k['link'] in show_group]]143 group_titles = productData_groups[-1]144 if 'previous' in request.form:145 for i in productData_groups:146 if i['id'] == request.form['previous']:147 ind = productData_groups.index(i)148 if ind != 0:149 show_group = productData_links[ind - 1]150 show_group = [[k for k in champagne if k['link'] in show_group]]151 group_titles = productData_groups[ind - 1]152 break153 else:154 show_group = productData_links[0]155 show_group = [[k for k in champagne if k['link'] in show_group]]156 group_titles = productData_groups[0]157 if 'delete_from_finished' in request.form:158 delete_id = request.form['delete_from_finished']159 Merger_DB['productData'].delete_one({'_id': delete_id})160 product_with_id = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find({'product_id': {'$exists': True}}))161 need_to_delete_list = [i for i in product_with_id if i['product_id'] == delete_id]162 for i in need_to_delete_list:163 Merger_DB['ШампанÑкое и игÑиÑÑое вино'].update({'_id': i['_id']}, {'$unset': {'in_productData': 1}}, upsert=True)164 # Saving data to files165 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())166 productData_file = list(Merger_DB['productData'].find())167 write_file('productData.json', productData_file)168 write_file('champagne.json', champagne)169 flash('ÐÑÑппа ÑÑпеÑно оÑпÑавлена на повÑоÑнÑÑ Ð¾Ð±ÑабоÑкÑ')170 return redirect('/finished_champagne')171 172 # ÐÐ¾Ð¼ÐµÑ Ð³ÑÑппÑ173 group_num = 0174 if group_titles:175 group_num = productData_groups.index(group_titles) + 1176 # ÑиÑло гоÑовÑÑ
гÑÑпп177 done = Merger_DB['productData'].count_documents({'section': 'ШампанÑкое и игÑиÑÑое вино'})178 return render_template('finished_champagne.html', groups=show_group, titles=group_titles, done=done, group_num=group_num)179@app.route('/finished_cognac', methods=['GET', 'POST'])180def finished_cognac():181 # for i in read_file('cognac.json'):182 # Merger_DB['ÐонÑÑк'].update({'_id': i['_id']}, {'$set': i}, upsert=True)183 #184 # for i in read_file('productData.json'):185 # Merger_DB['productData'].update({'_id': i['id']}, {'$set': i}, upsert=True)186 show_group = None187 group_titles = None188 cognac = list(Merger_DB['ÐонÑÑк'].find())189 merged_cognac = list(Merger_DB['productData'].find({'section': 'ÐонÑÑк'}))190 productData_links = [i['links'] for i in merged_cognac]191 productData_groups = [i for i in merged_cognac]192 if productData_links:193 show_group = productData_links[0]194 show_group = [[i for i in cognac if i['link'] in show_group]]195 group_titles = productData_groups[0]196 if 'search' in request.form:197 group_ind = int(request.form['search']) - 1198 if group_ind > len(merged_cognac) - 1:199 flash('У Ð²Ð°Ñ Ð½ÐµÑ ÑÑолÑко гÑÑпп')200 return redirect('/finished_cognac')201 show_group = productData_links[group_ind]202 show_group = [[i for i in cognac if i['link'] in show_group]]203 group_titles = productData_groups[group_ind]204 if 'next' in request.form:205 for i in productData_groups:206 if i['id'] == request.form['next']:207 ind = productData_groups.index(i)208 if ind != len(productData_groups) - 1:209 show_group = productData_links[ind + 1]210 show_group = [[k for k in cognac if k['link'] in show_group]]211 group_titles = productData_groups[ind + 1]212 break213 else:214 show_group = productData_links[-1]215 show_group = [[k for k in cognac if k['link'] in show_group]]216 group_titles = productData_groups[-1]217 if 'previous' in request.form:218 for i in productData_groups:219 if i['id'] == request.form['previous']:220 ind = productData_groups.index(i)221 if ind != 0:222 show_group = productData_links[ind - 1]223 show_group = [[k for k in cognac if k['link'] in show_group]]224 group_titles = productData_groups[ind - 1]225 break226 else:227 show_group = productData_links[0]228 show_group = [[k for k in cognac if k['link'] in show_group]]229 group_titles = productData_groups[0]230 if 'delete_from_finished' in request.form:231 delete_id = request.form['delete_from_finished']232 Merger_DB['productData'].delete_one({'_id': delete_id})233 product_with_id = list(Merger_DB['ÐонÑÑк'].find({'product_id': {'$exists': True}}))234 need_to_delete_list = [i for i in product_with_id if i['product_id'] == delete_id]235 for i in need_to_delete_list:236 Merger_DB['ÐонÑÑк'].update({'_id': i['_id']}, {'$unset': {'in_productData': 1}}, upsert=True)237 # Saving data to files238 cognac_file = list(Merger_DB['ÐонÑÑк'].find())239 productData_file = list(Merger_DB['productData'].find())240 write_file('productData.json', productData_file)241 write_file('whiskey.json', cognac_file)242 flash('ÐÑÑппа ÑÑпеÑно оÑпÑавлена на повÑоÑнÑÑ Ð¾Ð±ÑабоÑкÑ')243 return redirect('/finished_cognac')244 # ÐÐ¾Ð¼ÐµÑ Ð³ÑÑппÑ245 group_num = 0246 if group_titles:247 group_num = productData_groups.index(group_titles) + 1248 # ЧиÑло гоÑовÑÑ
249 done = Merger_DB['productData'].count_documents({'section': 'ÐонÑÑк'})250 return render_template('finished_cognac.html', groups=show_group, titles=group_titles, done=done, group_num=group_num)251@app.route('/finished_vodka', methods=['GET', 'POST'])252def finished_vodka():253 # for i in read_file('vodka.json'):254 # Merger_DB['Ðодка'].update({'_id': i['_id']}, {'$set': i}, upsert=True)255 #256 # for i in read_file('productData.json'):257 # Merger_DB['productData'].update({'_id': i['id']}, {'$set': i}, upsert=True)258 show_group = None259 group_titles = None260 vodka = list(Merger_DB['Ðодка'].find())261 merged_vodka = list(Merger_DB['productData'].find({'section': 'Ðодка'}))262 productData_links = [i['links'] for i in merged_vodka]263 productData_groups = [i for i in merged_vodka]264 if productData_links:265 show_group = productData_links[0]266 show_group = [[i for i in vodka if i['link'] in show_group]]267 group_titles = productData_groups[0]268 269 if 'search' in request.form:270 group_ind = int(request.form['search']) - 1271 if group_ind > len(merged_vodka):272 flash('У Ð²Ð°Ñ Ð½ÐµÑ ÑÑолÑко гÑÑпп')273 return redirect('/finished_vodka')274 show_group = productData_links[group_ind]275 show_group = [[i for i in vodka if i['link'] in show_group]]276 group_titles = productData_groups[group_ind]277 if 'next' in request.form:278 for i in productData_groups:279 if i['id'] == request.form['next']:280 ind = productData_groups.index(i)281 if ind != len(productData_groups)-1:282 show_group = productData_links[ind + 1]283 show_group = [[k for k in vodka if k['link'] in show_group]]284 group_titles = productData_groups[ind + 1]285 break286 else:287 show_group = productData_links[-1]288 show_group = [[k for k in vodka if k['link'] in show_group]]289 group_titles = productData_groups[-1]290 if 'previous' in request.form:291 for i in productData_groups:292 if i['id'] == request.form['previous']:293 ind = productData_groups.index(i)294 if ind != 0:295 show_group = productData_links[ind - 1]296 show_group = [[k for k in vodka if k['link'] in show_group]]297 group_titles = productData_groups[ind - 1]298 break299 else:300 show_group = productData_links[0]301 show_group = [[k for k in vodka if k['link'] in show_group]]302 group_titles = productData_groups[0]303 if 'delete_from_finished' in request.form:304 delete_id = request.form['delete_from_finished']305 Merger_DB['productData'].delete_one({'_id': delete_id})306 product_with_id = list(Merger_DB['Ðодка'].find({'product_id': {'$exists': True}}))307 need_to_delete_list = [i for i in product_with_id if i['product_id'] == delete_id]308 for i in need_to_delete_list:309 Merger_DB['Ðодка'].update({'_id': i['_id']}, {'$unset': {'in_productData': 1}}, upsert=True)310 # Saving data to files311 vodka_file = list(Merger_DB['Ðодка'].find())312 productData_file = list(Merger_DB['productData'].find())313 write_file('productData.json', productData_file)314 write_file('vodka.json', vodka_file)315 flash('ÐÑÑппа ÑÑпеÑно оÑпÑавлена на повÑоÑнÑÑ Ð¾Ð±ÑабоÑкÑ')316 return redirect('/finished_vodka')317 318 # ÐÐ¾Ð¼ÐµÑ Ð³ÑÑппÑ319 group_num = 0320 if group_titles:321 group_num = productData_groups.index(group_titles) + 1322 # ÑиÑло гоÑовÑÑ
гÑÑпп323 done = Merger_DB['productData'].count_documents({'section': 'Ðодка'})324 return render_template('finished_vodka.html', groups=show_group, titles=group_titles, done=done, group_num=group_num)325@app.route('/finished_whiskey', methods=['GET', 'POST'])326def finished_whiskey():327 328 # for i in read_file('whiskey.json'):329 # Merger_DB['ÐиÑки'].update({'_id': i['_id']}, {'$set': i}, upsert=True)330 #331 # for i in read_file('productData.json'):332 # Merger_DB['productData'].update({'_id': i['id']}, {'$set': i}, upsert=True)333 334 show_group = None335 group_titles = None336 whiskey = list(Merger_DB['ÐиÑки'].find())337 merged_whiskey = list(Merger_DB['productData'].find({'section': 'ÐиÑки'}))338 productData_links = [i['links'] for i in merged_whiskey]339 productData_groups = [i for i in merged_whiskey]340 if productData_links:341 show_group = productData_links[0]342 show_group = [[i for i in whiskey if i['link'] in show_group]]343 group_titles = productData_groups[0]344 345 if 'search' in request.form:346 group_ind = int(request.form['search']) - 1347 if group_ind > len(merged_whiskey) - 1:348 flash('У Ð²Ð°Ñ Ð½ÐµÑ ÑÑолÑко гÑÑпп')349 return redirect('/finished_whiskey')350 show_group = productData_links[group_ind]351 show_group = [[i for i in whiskey if i['link'] in show_group]]352 group_titles = productData_groups[group_ind]353 if 'next' in request.form:354 for i in productData_groups:355 if i['id'] == request.form['next']:356 ind = productData_groups.index(i)357 if ind != len(productData_groups)-1:358 show_group = productData_links[ind + 1]359 show_group = [[k for k in whiskey if k['link'] in show_group]]360 group_titles = productData_groups[ind + 1]361 break362 else:363 show_group = productData_links[-1]364 show_group = [[k for k in whiskey if k['link'] in show_group]]365 group_titles = productData_groups[-1]366 if 'previous' in request.form:367 for i in productData_groups:368 if i['id'] == request.form['previous']:369 ind = productData_groups.index(i)370 if ind != 0:371 show_group = productData_links[ind - 1]372 show_group = [[k for k in whiskey if k['link'] in show_group]]373 group_titles = productData_groups[ind - 1]374 break375 else:376 show_group = productData_links[0]377 show_group = [[k for k in whiskey if k['link'] in show_group]]378 group_titles = productData_groups[0]379 if 'delete_from_finished' in request.form:380 delete_id = request.form['delete_from_finished']381 Merger_DB['productData'].delete_one({'_id': delete_id})382 product_with_id = list(Merger_DB['ÐиÑки'].find({'product_id': {'$exists': True}}))383 384 need_to_delete_list = [i for i in product_with_id if i['product_id'] == delete_id]385 for i in need_to_delete_list:386 Merger_DB['ÐиÑки'].update({'_id': i['_id']}, {'$unset': {'in_productData': 1}}, upsert=True)387 # Saving data to files388 whiskey_file = list(Merger_DB['ÐиÑки'].find())389 productData_file = list(Merger_DB['productData'].find())390 write_file('productData.json', productData_file)391 write_file('whiskey.json', whiskey_file)392 flash('ÐÑÑппа ÑÑпеÑно оÑпÑавлена на повÑоÑнÑÑ Ð¾Ð±ÑабоÑкÑ')393 return redirect('/finished_whiskey')394 395 # ÐÐ¾Ð¼ÐµÑ Ð³ÑÑппÑ396 group_num = 0397 if group_titles:398 group_num = productData_groups.index(group_titles) + 1399 # ÑиÑло гоÑовÑÑ
гÑÑпп400 done = Merger_DB['productData'].count_documents({'section': 'ÐиÑки'})401 return render_template('finished_whiskey.html', groups=show_group, titles=group_titles, done=done, group_num=group_num)402@app.route('/naming_beer', methods=['GET', 'POST'])403def naming_beer():404 ip_address = request.remote_addr.replace('.', '')405 if request.method == 'GET':406 Merger_DB['del_list'].update({'_id': 'beer_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)407 show_group = None408 beer = list(Merger_DB['Ðиво'].find())409 group_id = numpy.unique(410 [i['product_id'] for i in beer if 'product_id' in i.keys() and not ('in_productData' in i.keys())])411 groups = list()412 products_with_id = [i for i in beer if 'product_id' in i.keys()]413 for i in group_id:414 group = [k for k in products_with_id if k['product_id'] == i]415 groups.append(group)416 if groups:417 show_group = [groups[0]]418 if 'saving' in request.form:419 beer = list(Merger_DB['Ðиво'].find())420 del_list = list(421 Merger_DB['del_list'].find({'$and': [{'_id': 'beer_del_list'}, {ip_address: {'$exists': True}}]}))422 if del_list:423 del_list = del_list[0][ip_address]424 for i in del_list:425 del_product = [k for k in beer if k['link'] == i]426 if del_product:427 # del_product[0]['identified'] = False428 # del_product[0].pop('product_id')429 Merger_DB['Ðиво'].update({'_id': del_product[0]['_id']},430 {'$set': {'identified': False}})431 Merger_DB['Ðиво'].update({'_id': del_product[0]['_id']},432 {'$unset': {'product_id': 1}})433 Merger_DB['del_list'].update({'_id': 'beer_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)434 product_dict = dict()435 fortress = request.form['fortress']436 product_dict['features'] = {}437 product_dict['features']['ÐÑепоÑÑÑ'] = None438 product_dict['images'] = {}439 product_dict['description'] = ''440 product_dict['section'] = 'Ðиво'441 product_dict['id'] = request.form['group_id']442 product_dict['name'] = request.form['title']443 if fortress:444 product_dict['features']['ÐÑепоÑÑÑ'] = float(fortress) if '.' in fortress else int(fortress)445 product_dict['features']['СÑÑана'] = request.form['country']446 product_dict['features']['ÐÑенд'] = request.form['brand']447 product_dict['features']['ЦвеÑ'] = request.form['color']448 product_dict['features']['ФилÑÑÑаÑиÑ'] = request.form['filtration']449 if product_dict['name'] and product_dict['features']['ÐÑепоÑÑÑ'] and product_dict['features']['СÑÑана'] and \450 product_dict['features']['ÐÑенд'] and product_dict['features'][451 'ЦвеÑ'] and product_dict['features']['ФилÑÑÑаÑиÑ']:452 beer = list(Merger_DB['Ðиво'].find())453 products = [i for i in beer if 'product_id' in i.keys()]454 product_dict['links'] = [i['link'] for i in products if i['product_id'] == product_dict['id']]455 product_dict['images']['default'] = [i['image'] for i in beer if i['link'] in product_dict['links']][0]456 Merger_DB['productData'].update({'_id': product_dict['id']}, {'$set': product_dict}, upsert=True)457 for i in beer:458 if 'product_id' in i.keys():459 if i['product_id'] == product_dict['id']:460 # i['in_productData'] = True461 # Merger_DB['ШампанÑкое и игÑиÑÑое вино'].update({'_id': i['_id']}, {'$set': i}, upsert=True)462 Merger_DB['Ðиво'].update({'_id': i['_id']},463 {'$set': {'in_productData': True}}, upsert=True)464 # saving data to files465 beer = list(Merger_DB['Ðиво'].find())466 write_file('beer.json', beer)467 productData = list(Merger_DB['productData'].find())468 write_file('productData.json', productData)469 flash('ÐпеÑаÑÐ¸Ñ Ð¿Ñоведена ÑÑпеÑно', 'success')470 return redirect('/naming_beer')471 else:472 # saving data to files473 beer = list(Merger_DB['Ðиво'].find())474 write_file('beer.json', beer)475 flash('ÐÑжно заполниÑÑ Ð²Ñе полÑ', category='error')476 return redirect('/naming_beer')477 if 'delete_from_group' in request.form:478 del_link = request.form['delete_from_group']479 del_list = list(480 Merger_DB['del_list'].find({'$and': [{'_id': 'beer_del_list'}, {ip_address: {'$exists': True}}]}))481 if del_list:482 del_list = del_list[0][ip_address]483 if not (del_link in del_list):484 del_list.append(del_link)485 else:486 del_list.remove(del_link)487 Merger_DB['del_list'].update({'_id': 'beer_del_list'}, {'$set': {ip_address: del_list}}, upsert=True)488 if 'next' in request.form:489 for i in groups:490 if str(i) == str(request.form['next']):491 if groups.index(i) != len(groups) - 1:492 show_group = [groups[groups.index(i) + 1]]493 break494 else:495 show_group = [groups[-1]]496 Merger_DB['del_list'].update({'_id': 'beer_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)497 if 'previous' in request.form:498 for i in groups:499 if str(i) == str(request.form['previous']):500 if groups.index(i) != 0:501 show_group = [groups[groups.index(i) - 1]]502 break503 Merger_DB['del_list'].update({'_id': 'beer_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)504 # ÑиÑло негоÑовÑÑ
гÑÑпп505 undone = len(groups)506 return render_template('naming_beer.html', groups=show_group, undone=undone)507@app.route('/naming_champagne', methods=['GET', 'POST'])508def naming_champagne():509 ip_address = request.remote_addr.replace('.', '')510 if request.method == 'GET':511 Merger_DB['del_list'].update({'_id': 'champagne_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)512 show_group = None513 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())514 group_id = numpy.unique(515 [i['product_id'] for i in champagne if 'product_id' in i.keys() and not ('in_productData' in i.keys())])516 groups = list()517 products_with_id = [i for i in champagne if 'product_id' in i.keys()]518 for i in group_id:519 group = [k for k in products_with_id if k['product_id'] == i]520 groups.append(group)521 if groups:522 show_group = [groups[0]]523 524 if 'saving' in request.form:525 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())526 del_list = list(Merger_DB['del_list'].find({'$and': [{'_id': 'champagne_del_list'}, {ip_address: {'$exists': True}}]}))527 if del_list:528 del_list = del_list[0][ip_address]529 for i in del_list:530 del_product = [k for k in champagne if k['link'] == i]531 if del_product:532 # del_product[0]['identified'] = False533 # del_product[0].pop('product_id')534 Merger_DB['ШампанÑкое и игÑиÑÑое вино'].update({'_id': del_product[0]['_id']}, {'$set': {'identified': False}})535 Merger_DB['ШампанÑкое и игÑиÑÑое вино'].update({'_id': del_product[0]['_id']}, {'$unset': {'product_id': 1}})536 Merger_DB['del_list'].update({'_id': 'champagne_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)537 538 product_dict = dict()539 fortress = request.form['fortress']540 product_dict['features'] = {}541 product_dict['features']['ÐÑепоÑÑÑ'] = None542 product_dict['images'] = {}543 product_dict['description'] = ''544 product_dict['section'] = 'ШампанÑкое и игÑиÑÑое вино'545 product_dict['id'] = request.form['group_id']546 product_dict['name'] = request.form['title']547 if fortress:548 product_dict['features']['ÐÑепоÑÑÑ'] = float(fortress) if '.' in fortress else int(fortress)549 product_dict['features']['СÑÑана'] = request.form['country']550 product_dict['features']['ÐÑенд'] = request.form['brand']551 product_dict['features']['Тип'] = request.form['type']552 product_dict['features']['ЦвеÑ'] = request.form['color']553 product_dict['features']['СаÑ
аÑ'] = request.form['sugar']554 555 if product_dict['name'] and product_dict['features']['ÐÑепоÑÑÑ'] and product_dict['features']['СÑÑана'] and product_dict['features']['ÐÑенд'] and product_dict['features']['Тип'] and product_dict['features']['ЦвеÑ'] and product_dict['features']['СаÑ
аÑ']:556 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())557 products = [i for i in champagne if 'product_id' in i.keys()]558 product_dict['links'] = [i['link'] for i in products if i['product_id'] == product_dict['id']]559 product_dict['images']['default'] = [i['image'] for i in champagne if i['link'] in product_dict['links']][0]560 Merger_DB['productData'].update({'_id': product_dict['id']}, {'$set': product_dict}, upsert=True)561 for i in champagne:562 if 'product_id' in i.keys():563 if i['product_id'] == product_dict['id']:564 # i['in_productData'] = True565 # Merger_DB['ШампанÑкое и игÑиÑÑое вино'].update({'_id': i['_id']}, {'$set': i}, upsert=True)566 Merger_DB['ШампанÑкое и игÑиÑÑое вино'].update({'_id': i['_id']}, {'$set': {'in_productData': True}}, upsert=True)567 # saving data to files568 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())569 write_file('champagne.json', champagne)570 productData = list(Merger_DB['productData'].find())571 write_file('productData.json', productData)572 flash('ÐпеÑаÑÐ¸Ñ Ð¿Ñоведена ÑÑпеÑно', 'success')573 return redirect('/naming_champagne')574 else:575 # saving data to files576 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())577 write_file('champagne.json', champagne)578 flash('ÐÑжно заполниÑÑ Ð²Ñе полÑ', category='error')579 return redirect('/naming_champagne')580 if 'delete_from_group' in request.form:581 del_link = request.form['delete_from_group']582 del_list = list(Merger_DB['del_list'].find({'$and': [{'_id': 'champagne_del_list'}, {ip_address: {'$exists': True}}]}))583 if del_list:584 del_list = del_list[0][ip_address]585 if not (del_link in del_list):586 del_list.append(del_link)587 else:588 del_list.remove(del_link)589 Merger_DB['del_list'].update({'_id': 'champagne_del_list'}, {'$set': {ip_address: del_list}}, upsert=True)590 if 'next' in request.form:591 for i in groups:592 if str(i) == str(request.form['next']):593 if groups.index(i) != len(groups) - 1:594 show_group = [groups[groups.index(i) + 1]]595 break596 else:597 show_group = [groups[-1]]598 Merger_DB['del_list'].update({'_id': 'champagne_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)599 if 'previous' in request.form:600 for i in groups:601 if str(i) == str(request.form['previous']):602 if groups.index(i) != 0:603 show_group = [groups[groups.index(i) - 1]]604 break605 Merger_DB['del_list'].update({'_id': 'champagne_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)606 # ÑиÑло негоÑовÑÑ
гÑÑпп607 undone = len(groups)608 return render_template('naming_champagne.html', groups=show_group, undone=undone)609@app.route('/naming_cognac', methods=['GET', 'POST'])610def naming_cognac():611 ip_address = request.remote_addr.replace('.', '')612 if request.method == 'GET':613 Merger_DB['del_list'].update({'_id': 'cognac_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)614 show_group = None615 cognac = list(Merger_DB['ÐонÑÑк'].find())616 group_id = numpy.unique([i['product_id'] for i in cognac if 'product_id' in i.keys() and not ('in_productData' in i.keys())])617 groups = list()618 products_with_id = [i for i in cognac if 'product_id' in i.keys()]619 for i in group_id:620 group = [k for k in products_with_id if k['product_id'] == i]621 groups.append(group)622 if groups:623 show_group = [groups[0]]624 if 'saving' in request.form:625 cognac = list(Merger_DB['ÐонÑÑк'].find())626 del_list = list(Merger_DB['del_list'].find({'$and': [{'_id': 'cognac_del_list'}, {ip_address: {'$exists': True}}]}))627 if del_list:628 del_list = del_list[0][ip_address]629 for i in del_list:630 del_product = [k for k in cognac if k['link'] == i]631 if del_product:632 # del_product[0]['identified'] = False633 # del_product[0].pop('product_id')634 Merger_DB['ÐонÑÑк'].update({'_id': del_product[0]['_id']}, {'$set': {'identified': False}})635 Merger_DB['ÐонÑÑк'].update({'_id': del_product[0]['_id']}, {'$unset': {'product_id': 1}})636 Merger_DB['del_list'].update({'_id': 'cognac_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)637 product_dict = dict()638 exposure = request.form['exposure']639 fortress = request.form['fortress']640 product_dict['features'] = {}641 product_dict['features']['ÐÑепоÑÑÑ'] = None642 product_dict['features']['ÐÑдеÑжка'] = None643 if exposure and fortress:644 product_dict['features']['ÐÑепоÑÑÑ'] = float(fortress) if '.' in fortress else int(fortress)645 product_dict['features']['ÐÑдеÑжка'] = float(exposure) if '.' in exposure else int(exposure)646 product_dict['images'] = {}647 product_dict['description'] = ''648 product_dict['section'] = 'ÐонÑÑк'649 product_dict['id'] = request.form['group_id']650 product_dict['name'] = request.form['title']651 product_dict['features']['СÑÑана'] = request.form['country']652 product_dict['features']['ÐÑенд'] = request.form['brand']653 product_dict['features']['ÐлаÑÑ'] = request.form['type']654 if product_dict['name'] and product_dict['features']['СÑÑана'] and product_dict['features']['ÐÑенд'] and product_dict['features']['ÐлаÑÑ'] and product_dict['features']['ÐÑепоÑÑÑ'] and product_dict['features']['ÐÑдеÑжка']:655 cognac = list(Merger_DB['ÐонÑÑк'].find())656 products = [i for i in cognac if 'product_id' in i.keys()]657 product_dict['links'] = [i['link'] for i in products if i['product_id'] == product_dict['id']]658 product_dict['images']['default'] = [i['image'] for i in cognac if i['link'] in product_dict['links']][0]659 Merger_DB['productData'].update({'_id': product_dict['id']}, {'$set': product_dict}, upsert=True)660 for i in cognac:661 if 'product_id' in i.keys():662 if i['product_id'] == product_dict['id']:663 # i['in_productData'] = True664 Merger_DB['ÐонÑÑк'].update({'_id': i['_id']}, {'$set': {'in_productData': True}}, upsert=True)665 # saving data to files666 cognac = list(Merger_DB['ÐонÑÑк'].find())667 write_file('cognac.json', cognac)668 productData = list(Merger_DB['productData'].find())669 write_file('productData.json', productData)670 flash('ÐпеÑаÑÐ¸Ñ Ð¿Ñоведена ÑÑпеÑно', category='success')671 return redirect('/naming_cognac')672 else:673 # saving data to files674 cognac = list(Merger_DB['ÐонÑÑк'].find())675 write_file('cognac.json', cognac)676 flash('ÐÑжно заполниÑÑ Ð²Ñе полÑ', category='error')677 return redirect('/naming_cognac')678 if 'delete_from_group' in request.form:679 del_link = request.form['delete_from_group']680 del_list = list(Merger_DB['del_list'].find({'$and': [{'_id': 'cognac_del_list'}, {ip_address: {'$exists': True}}]}))681 if del_list:682 del_list = del_list[0][ip_address]683 if not (del_link in del_list):684 del_list.append(del_link)685 else:686 del_list.remove(del_link)687 Merger_DB['del_list'].update({'_id': 'cognac_del_list'}, {'$set': {ip_address: del_list}}, upsert=True)688 if 'next' in request.form:689 for i in groups:690 if str(i) == str(request.form['next']):691 if groups.index(i) != len(groups) - 1:692 show_group = [groups[groups.index(i) + 1]]693 break694 else:695 show_group = [groups[-1]]696 Merger_DB['del_list'].update({'_id': 'cognac_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)697 if 'previous' in request.form:698 for i in groups:699 if str(i) == str(request.form['previous']):700 if groups.index(i) != 0:701 show_group = [groups[groups.index(i) - 1]]702 break703 Merger_DB['del_list'].update({'_id': 'cognac_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)704 # ÑиÑло негоÑовÑÑ
гÑÑпп705 undone = len(groups)706 return render_template('naming_cognac.html', groups=show_group, undone=undone)707@app.route('/naming_vodka', methods=['GET', 'POST'])708def naming_vodka():709 ip_address = request.remote_addr.replace('.', '')710 if request.method == 'GET':711 Merger_DB['del_list'].update({'_id': 'vodka_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)712 show_group = None713 vodka = list(Merger_DB['Ðодка'].find())714 group_id = numpy.unique([i['product_id'] for i in vodka if 'product_id' in i.keys() and not ('in_productData' in i.keys())])715 groups = list()716 products_with_id = [i for i in vodka if 'product_id' in i.keys()]717 for i in group_id:718 group = [k for k in products_with_id if k['product_id'] == i]719 groups.append(group)720 if groups:721 show_group = [groups[0]]722 723 if 'saving' in request.form:724 vodka = list(Merger_DB['Ðодка'].find())725 del_list = list(Merger_DB['del_list'].find({'$and': [{'_id': 'vodka_del_list'}, {ip_address: {'$exists': True}}]}))726 if del_list:727 del_list = del_list[0][ip_address]728 for i in del_list:729 del_product = [k for k in vodka if k['link'] == i]730 if del_product:731 del_product[0]['identified'] = False732 del_product[0].pop('product_id')733 # vodka[vodka.index([n for n in vodka if n['link'] == i][0])] = del_product[0]734 Merger_DB['Ðодка'].update({'_id': del_product[0]['_id']}, {'$set': del_product[0]})735 Merger_DB['Ðодка'].update({'_id': del_product[0]['_id']}, {'$unset': {'product_id': 1}})736 Merger_DB['del_list'].update({'_id': 'vodka_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)737 product_dict = dict()738 fortress = request.form['fortress']739 product_dict['features'] = {}740 product_dict['features']['ÐÑепоÑÑÑ'] = None741 if fortress:742 product_dict['features']['ÐÑепоÑÑÑ'] = float(fortress) if '.' in fortress else int(fortress)743 product_dict['images'] = {}744 product_dict['description'] = ''745 product_dict['section'] = 'Ðодка'746 product_dict['id'] = request.form['group_id']747 product_dict['name'] = request.form['title']748 product_dict['features']['СÑÑана'] = request.form['country']749 product_dict['features']['ÐÑенд'] = request.form['brand']750 product_dict['features']['Тип'] = request.form['type']751 if product_dict['name'] and product_dict['features']['СÑÑана'] and product_dict['features']['ÐÑенд'] and product_dict['features']['Тип'] and product_dict['features']['ÐÑепоÑÑÑ']:752 vodka = list(Merger_DB['Ðодка'].find())753 products = [i for i in vodka if 'product_id' in i.keys()]754 product_dict['links'] = [i['link'] for i in products if i['product_id'] == product_dict['id']]755 product_dict['images']['default'] = [i['image'] for i in vodka if i['link'] in product_dict['links']][0]756 Merger_DB['productData'].update({'_id': product_dict['id']}, {'$set': product_dict}, upsert=True)757 for i in vodka:758 if 'product_id' in i.keys():759 if i['product_id'] == product_dict['id']:760 i['in_productData'] = True761 Merger_DB['Ðодка'].update({'_id': i['_id']}, {'$set': i}, upsert=True)762 763 # saving data to files764 vodka = list(Merger_DB['Ðодка'].find())765 write_file('vodka.json', vodka)766 productData = list(Merger_DB['productData'].find())767 write_file('productData.json', productData)768 769 flash('ÐпеÑаÑÐ¸Ñ Ð¿Ñоведена ÑÑпеÑно', category='success')770 return redirect('/naming_vodka')771 else:772 # saving data to files773 vodka = list(Merger_DB['Ðодка'].find())774 write_file('vodka.json', vodka)775 flash('ÐÑжно заполниÑÑ Ð²Ñе полÑ', category='error')776 return redirect('/naming_vodka')777 if 'delete_from_group' in request.form:778 del_link = request.form['delete_from_group']779 del_list = list(Merger_DB['del_list'].find({'$and': [{'_id': 'vodka_del_list'}, {ip_address: {'$exists': True}}]}))780 if del_list:781 del_list = del_list[0][ip_address]782 if not (del_link in del_list):783 del_list.append(del_link)784 else:785 del_list.remove(del_link)786 Merger_DB['del_list'].update({'_id': 'vodka_del_list'}, {'$set': {ip_address: del_list}}, upsert=True)787 if 'next' in request.form:788 for i in groups:789 if str(i) == str(request.form['next']):790 if groups.index(i) != len(groups)-1:791 show_group = [groups[groups.index(i)+1]]792 break793 else:794 show_group = [groups[-1]]795 Merger_DB['del_list'].update({'_id': 'vodka_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)796 if 'previous' in request.form:797 for i in groups:798 if str(i) == str(request.form['previous']):799 if groups.index(i) != 0:800 show_group = [groups[groups.index(i) - 1]]801 break802 Merger_DB['del_list'].update({'_id': 'vodka_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)803 # ÑиÑло негоÑовÑÑ
гÑÑпп804 undone = len(groups)805 return render_template('naming_vodka.html', groups=show_group, undone=undone)806@app.route('/naming_whiskey', methods=['GET', 'POST'])807def naming_whiskey():808 ip_address = request.remote_addr.replace('.', '')809 if request.method == 'GET':810 Merger_DB['del_list'].update({'_id': 'whiskey_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)811 show_group = None812 whiskey = list(Merger_DB['ÐиÑки'].find())813 group_id = numpy.unique([i['product_id'] for i in whiskey if 'product_id' in i.keys() and not ('in_productData' in i.keys())])814 groups = list()815 products_with_id = [i for i in whiskey if 'product_id' in i.keys()]816 for i in group_id:817 group = [k for k in products_with_id if k['product_id'] == i]818 groups.append(group)819 if groups:820 show_group = [groups[0]]821 822 if 'saving' in request.form:823 whiskey = list(Merger_DB['ÐиÑки'].find())824 del_list = list(Merger_DB['del_list'].find({'$and': [{'_id': 'whiskey_del_list'}, {ip_address: {'$exists': True}}]}))825 if del_list:826 del_list = del_list[0][ip_address]827 for i in del_list:828 del_product = [k for k in whiskey if k['link'] == i]829 if del_product:830 del_product[0]['identified'] = False831 del_product[0].pop('product_id')832 Merger_DB['ÐиÑки'].update({'_id': del_product[0]['_id']}, {'$set': del_product[0]})833 Merger_DB['ÐиÑки'].update({'_id': del_product[0]['_id']}, {'$unset': {'product_id': 1}})834 Merger_DB['del_list'].update({'_id': 'whiskey_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)835 product_dict = dict()836 exposure = request.form['exposure']837 fortress = request.form['fortress']838 product_dict['features'] = {}839 product_dict['features']['ÐÑепоÑÑÑ'] = None840 product_dict['features']['ÐÑдеÑжка'] = None841 if exposure and fortress:842 product_dict['features']['ÐÑепоÑÑÑ'] = float(fortress) if '.' in fortress else int(fortress)843 product_dict['features']['ÐÑдеÑжка'] = float(exposure) if '.' in exposure else int(exposure)844 product_dict['images'] = {}845 product_dict['description'] = ''846 product_dict['section'] = 'ÐиÑки'847 product_dict['id'] = request.form['group_id']848 product_dict['name'] = request.form['title']849 product_dict['features']['СÑÑана'] = request.form['country']850 product_dict['features']['ÐÑенд'] = request.form['brand']851 product_dict['features']['Тип'] = request.form['type']852 if product_dict['name'] and product_dict['features']['СÑÑана'] and product_dict['features']['ÐÑенд'] and product_dict['features']['Тип'] and product_dict['features']['ÐÑдеÑжка'] and product_dict['features']['ÐÑепоÑÑÑ']:853 print('OKKKKKKK')854 whiskey = list(Merger_DB['ÐиÑки'].find())855 products = [i for i in whiskey if 'product_id' in i.keys()]856 product_dict['links'] = [i['link'] for i in products if i['product_id'] == product_dict['id']]857 product_dict['images']['default'] = [i['image'] for i in whiskey if i['link'] in product_dict['links'] and 'image' in i.keys()][0]858 Merger_DB['productData'].update({'_id': product_dict['id']}, {'$set': product_dict}, upsert=True)859 860 for i in whiskey:861 if 'product_id' in i.keys():862 if i['product_id'] == product_dict['id']:863 # ind = whiskey.index(i)864 i['in_productData'] = True865 # whiskey[ind] = i866 Merger_DB['ÐиÑки'].update({'_id': i['_id']}, {'$set': i}, upsert=True)867 # saving data to files868 whiskey = list(Merger_DB['ÐиÑки'].find())869 write_file('whiskey.json', whiskey)870 productData = list(Merger_DB['productData'].find())871 write_file('productData.json', productData)872 873 flash('ÐпеÑаÑÐ¸Ñ Ð¿Ñоведена ÑÑпеÑно', category='success')874 return redirect('/naming_whiskey')875 else:876 # saving data to files877 whiskey = list(Merger_DB['ÐиÑки'].find())878 write_file('whiskey.json', whiskey)879 flash('ÐÑжно заполниÑÑ Ð²Ñе полÑ', category='error')880 return redirect('/naming_whiskey')881 if 'delete_from_group' in request.form:882 del_link = request.form['delete_from_group']883 del_list = list(Merger_DB['del_list'].find({'$and': [{'_id': 'whiskey_del_list'}, {ip_address: {'$exists': True}}]}))884 if del_list:885 del_list = del_list[0][ip_address]886 if not (del_link in del_list):887 del_list.append(del_link)888 else:889 del_list.remove(del_link)890 Merger_DB['del_list'].update({'_id': 'whiskey_del_list'}, {'$set': {ip_address: del_list}}, upsert=True)891 if 'next' in request.form:892 for i in groups:893 if str(i) == str(request.form['next']):894 if groups.index(i) != len(groups)-1:895 show_group = [groups[groups.index(i)+1]]896 break897 else:898 show_group = [groups[-1]]899 Merger_DB['del_list'].update({'_id': 'whiskey_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)900 if 'previous' in request.form:901 for i in groups:902 if str(i) == str(request.form['previous']):903 if groups.index(i) != 0:904 show_group = [groups[groups.index(i) - 1]]905 break906 Merger_DB['del_list'].update({'_id': 'whiskey_del_list'}, {'$unset': {ip_address: 1}}, upsert=True)907 908 # ÑиÑло негоÑовÑÑ
гÑÑпп909 undone = len(groups)910 return render_template('naming_whiskey.html', groups=show_group, undone=undone)911@app.route('/grouping_beer/', methods=['GET', 'POST'])912def grouping_beer():913 ip_address = request.remote_addr.replace('.', '')914 if request.method == 'GET':915 Merger_DB['link_list'].update({'_id': 'beer_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)916 search = ''917 result_list = []918 beer = list(Merger_DB['Ðиво'].find())919 skip_list = list(Merger_DB['skip_list'].find({'_id': 'beer_skip_list'}))920 if skip_list:921 skip_list = skip_list[0]['skip_list']922 main_drink = [i for i in beer if i['identified'] is False and not (i['link'] in skip_list)]923 if main_drink:924 main_drink = main_drink[0]925 else:926 if skip_list:927 del skip_list[0]928 main_drink = [i for i in beer if i['identified'] is False and not (i['link'] in skip_list)]929 if main_drink:930 main_drink = main_drink[0]931 Merger_DB['skip_list'].update({'_id': 'beer_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)932 if "index" in request.form:933 link = request.form['index']934 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'beer_link_list'}, {ip_address: {'$exists': True}}]}))935 if link_list:936 link_list = link_list[0][ip_address]937 if link in link_list:938 link_list.remove(link)939 else:940 link_list.append(link)941 Merger_DB['link_list'].update({'_id': 'beer_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)942 if 'add_to_group' in request.form:943 article = request.form['add_to_group']944 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'beer_link_list'}, {ip_address: {'$exists': True}}]}))945 if link_list:946 link_list = link_list[0][ip_address]947 if article in link_list:948 link_list.remove(article)949 else:950 link_list.append(article)951 Merger_DB['link_list'].update({'_id': 'beer_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)952 if 'skip' in request.form:953 Merger_DB['link_list'].update({'_id': 'beer_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)954 skip_list = list(Merger_DB['skip_list'].find({'_id': 'beer_skip_list'}))955 if skip_list:956 skip_list = skip_list[0]['skip_list']957 if not (request.form['skip'] in skip_list):958 skip_list.append(request.form['skip'])959 main_drink = [i for i in beer if i['identified'] is False and not (i['link'] in skip_list)]960 if main_drink:961 main_drink = main_drink[0]962 else:963 if skip_list:964 del skip_list[0]965 main_drink = [i for i in beer if i['identified'] is False and not (i['link'] in skip_list)]966 if main_drink:967 main_drink = main_drink[0]968 Merger_DB['skip_list'].update({'_id': 'beer_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)969 if 'search' in request.form:970 search = request.form['search']971 result_list = [i for i in beer if search.lower() in i['name'].lower() and not (i is main_drink)]972 if 'saving' in request.form:973 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'beer_link_list'}, {ip_address: {'$exists': True}}]}))974 if link_list:975 link_list = link_list[0][ip_address]976 match = [i for i in link_list if i.isdigit()]977 if len(match) > 1:978 flash('ÐÑибка: ÐÑ Ð¼Ð¾Ð¶ÐµÑе добавиÑÑ Ð½Ð°Ð¿Ð¸Ñок ÑолÑко в Ð¾Ð´Ð½Ñ Ð³ÑÑппÑ')979 Merger_DB['link_list'].update({'_id': 'beer_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)980 return redirect('/grouping_beer')981 elif len(match) == 1:982 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'beer_link_list'}, {ip_address: {'$exists': True}}]}))983 if link_list:984 link_list = link_list[0][ip_address]985 link_list.remove(match[0])986 if main_drink:987 link_list.append(main_drink['link'])988 Merger_DB['link_list'].update({'_id': 'beer_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)989 product_id = match[0]990 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'beer_link_list'}, {ip_address: {'$exists': True}}]}))991 if link_list:992 link_list = link_list[0][ip_address]993 for i in link_list:994 drink = [k for k in beer if k['link'] == i][0]995 ind = beer.index(drink)996 drink['identified'] = True997 drink['product_id'] = product_id998 if not ('id' in beer[ind].keys()):999 drink['id'] = take_article()1000 Merger_DB['Ðиво'].update({'_id': drink['_id']}, {'$set': drink}, upsert=True)1001 beer = list(Merger_DB['Ðиво'].find())1002 main_drink = [i for i in beer if i['identified'] is False and not (i['link'] in skip_list)]1003 if main_drink:1004 main_drink = main_drink[0]1005 else:1006 skip_list = list(Merger_DB['skip_list'].find({'_id': 'beer_skip_list'}))1007 if skip_list:1008 skip_list = skip_list[0]['skip_list']1009 if skip_list:1010 del skip_list[0]1011 main_drink = [i for i in beer if1012 i['identified'] is False and not (i['link'] in skip_list)]1013 if main_drink:1014 main_drink = main_drink[0]1015 Merger_DB['skip_list'].update({'_id': 'beer_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1016 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'beer_link_list'}, {ip_address: {'$exists': True}}]}))1017 if link_list:1018 link_list = link_list[0][ip_address]1019 productData = list(Merger_DB['productData'].find({'section': 'Ðиво'}))1020 item_in_PD = [i for i in productData if i['id'] == product_id]1021 if item_in_PD:1022 item_in_PD_index = productData.index(item_in_PD[0])1023 for i in link_list:1024 item_in_PD[0]['links'].append(i)1025 Merger_DB['productData'].update({'_id': item_in_PD[0]['id']}, {'$set': item_in_PD[0]}, upsert=True)1026 beer = list(Merger_DB['Ðиво'].find())1027 need_change = [i for i in beer if i['link'] in link_list]1028 for i in need_change:1029 i['in_productData'] = True1030 Merger_DB['Ðиво'].update({'_id': i['_id']}, {'$set': i}, upsert=True)1031 Merger_DB['link_list'].update({'_id': 'beer_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1032 beer = list(Merger_DB['Ðиво'].find())1033 write_file('beer.json', beer)1034 productData = list(Merger_DB['productData'].find())1035 write_file('productData.json', productData)1036 return redirect('/beer_grouping_prove')1037 else:1038 if main_drink:1039 link_list.append(main_drink['link'])1040 product_id = take_article()1041 for i in link_list:1042 drink = [k for k in beer if k['link'] == i][0]1043 ind = beer.index(drink)1044 drink['identified'] = True1045 drink['product_id'] = product_id1046 if not ('id' in beer[ind].keys()):1047 drink['id'] = take_article()1048 Merger_DB['Ðиво'].update({'_id': drink['_id']}, {'$set': drink}, upsert=True)1049 Merger_DB['link_list'].update({'_id': 'beer_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1050 beer = list(Merger_DB['Ðиво'].find())1051 main_drink = [i for i in beer if i['identified'] is False and not (i['link'] in skip_list)]1052 if main_drink:1053 main_drink = main_drink[0]1054 else:1055 skip_list = list(Merger_DB['skip_list'].find({'_id': 'beer_skip_list'}))1056 if skip_list:1057 skip_list = skip_list[0]['skip_list']1058 if skip_list:1059 del skip_list[0]1060 main_drink = [i for i in beer if i['identified'] is False and not (i['link'] in skip_list)]1061 if main_drink:1062 main_drink = main_drink[0]1063 Merger_DB['skip_list'].update({'_id': 'beer_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1064 # saving data to files1065 beer = list(Merger_DB['Ðиво'].find())1066 write_file('beer.json', beer)1067 return redirect('/beer_grouping_prove')1068 group_id = numpy.unique([i['product_id'] for i in result_list if 'product_id' in i.keys()])1069 groups = list()1070 products_with_id = [i for i in beer if 'product_id' in i.keys()]1071 for i in group_id:1072 group = [k for k in products_with_id if k['product_id'] == i]1073 groups.append(group)1074 result_list = [i for i in result_list if not (i in group)]1075 # ÑиÑло неÑгÑÑппиÑованнÑÑ
напиÑков1076 undone = Merger_DB['Ðиво'].count_documents({'identified': False})1077 # ÐомеÑа гÑÑпп в гÑÑппиÑовке1078 productData = list(Merger_DB['productData'].find({'section': 'Ðиво'}))1079 new_nums = []1080 if groups:1081 # group_nums = numpy.unique([k[0]['product_id'] for k in groups if 'product_id' in k[0].keys()])1082 group_nums = numpy.unique([k[0]['product_id'] for k in groups if 'in_productData' in k[0].keys()])1083 group_nums = list(group_nums)1084 if group_nums:1085 print(group_nums)1086 for i in group_nums:1087 new_nums.append(productData.index([k for k in productData if k['id'] == i][0]) + 1)1088 new_group = []1089 for i in groups:1090 if 'in_productData' in i[0].keys():1091 new_group.append(i)1092 for i in groups:1093 if not (i in new_group):1094 new_group.append(i)1095 groups = new_group1096 return render_template('grouping_beer.html', main_drink=main_drink, products=result_list, groups=groups, undone=undone, group_nums=new_nums)1097@app.route('/grouping_champagne/', methods=['GET', 'POST'])1098def grouping_champagne():1099 ip_address = request.remote_addr.replace('.', '')1100 if request.method == 'GET':1101 Merger_DB['link_list'].update({'_id': 'champagne_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1102 search = ''1103 result_list = []1104 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())1105 skip_list = list(Merger_DB['skip_list'].find({'_id': 'champagne_skip_list'}))1106 if skip_list:1107 skip_list = skip_list[0]['skip_list']1108 main_drink = [i for i in champagne if i['identified'] is False and not (i['link'] in skip_list)]1109 if main_drink:1110 main_drink = main_drink[0]1111 else:1112 if skip_list:1113 del skip_list[0]1114 main_drink = [i for i in champagne if i['identified'] is False and not (i['link'] in skip_list)]1115 if main_drink:1116 main_drink = main_drink[0]1117 Merger_DB['skip_list'].update({'_id': 'champagne_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1118 if "index" in request.form:1119 link = request.form['index']1120 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'champagne_link_list'}, {ip_address: {'$exists': True}}]}))1121 if link_list:1122 link_list = link_list[0][ip_address]1123 if link in link_list:1124 link_list.remove(link)1125 else:1126 link_list.append(link)1127 Merger_DB['link_list'].update({'_id': 'champagne_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1128 if 'add_to_group' in request.form:1129 article = request.form['add_to_group']1130 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'champagne_link_list'}, {ip_address: {'$exists': True}}]}))1131 if link_list:1132 link_list = link_list[0][ip_address]1133 if article in link_list:1134 link_list.remove(article)1135 else:1136 link_list.append(article)1137 Merger_DB['link_list'].update({'_id': 'champagne_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1138 if 'skip' in request.form:1139 Merger_DB['link_list'].update({'_id': 'champagne_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1140 skip_list = list(Merger_DB['skip_list'].find({'_id': 'champagne_skip_list'}))1141 if skip_list:1142 skip_list = skip_list[0]['skip_list']1143 if not (request.form['skip'] in skip_list):1144 skip_list.append(request.form['skip'])1145 main_drink = [i for i in champagne if i['identified'] is False and not (i['link'] in skip_list)]1146 if main_drink:1147 main_drink = main_drink[0]1148 else:1149 if skip_list:1150 del skip_list[0]1151 main_drink = [i for i in champagne if i['identified'] is False and not (i['link'] in skip_list)]1152 if main_drink:1153 main_drink = main_drink[0]1154 Merger_DB['skip_list'].update({'_id': 'champagne_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1155 if 'search' in request.form:1156 search = request.form['search']1157 result_list = [i for i in champagne if search.lower() in i['name'].lower() and not (i is main_drink)]1158 if 'saving' in request.form:1159 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'champagne_link_list'}, {ip_address: {'$exists': True}}]}))1160 if link_list:1161 link_list = link_list[0][ip_address]1162 match = [i for i in link_list if i.isdigit()]1163 if len(match) > 1:1164 flash('ÐÑибка: ÐÑ Ð¼Ð¾Ð¶ÐµÑе добавиÑÑ Ð½Ð°Ð¿Ð¸Ñок ÑолÑко в Ð¾Ð´Ð½Ñ Ð³ÑÑппÑ')1165 Merger_DB['link_list'].update({'_id': 'champagne_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1166 return redirect('/grouping_champagne')1167 elif len(match) == 1:1168 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'champagne_link_list'}, {ip_address: {'$exists': True}}]}))1169 if link_list:1170 link_list = link_list[0][ip_address]1171 link_list.remove(match[0])1172 if main_drink:1173 link_list.append(main_drink['link'])1174 Merger_DB['link_list'].update({'_id': 'champagne_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1175 product_id = match[0]1176 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'champagne_link_list'}, {ip_address: {'$exists': True}}]}))1177 if link_list:1178 link_list = link_list[0][ip_address]1179 for i in link_list:1180 drink = [k for k in champagne if k['link'] == i][0]1181 ind = champagne.index(drink)1182 drink['identified'] = True1183 drink['product_id'] = product_id1184 if not ('id' in champagne[ind].keys()):1185 drink['id'] = take_article()1186 Merger_DB['ШампанÑкое и игÑиÑÑое вино'].update({'_id': drink['_id']}, {'$set': drink}, upsert=True)1187 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())1188 main_drink = [i for i in champagne if i['identified'] is False and not (i['link'] in skip_list)]1189 if main_drink:1190 main_drink = main_drink[0]1191 else:1192 skip_list = list(Merger_DB['skip_list'].find({'_id': 'champagne_skip_list'}))1193 if skip_list:1194 skip_list = skip_list[0]['skip_list']1195 if skip_list:1196 del skip_list[0]1197 main_drink = [i for i in champagne if1198 i['identified'] is False and not (i['link'] in skip_list)]1199 if main_drink:1200 main_drink = main_drink[0]1201 Merger_DB['skip_list'].update({'_id': 'champagne_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1202 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'champagne_link_list'}, {ip_address: {'$exists': True}}]}))1203 if link_list:1204 link_list = link_list[0][ip_address]1205 productData = list(Merger_DB['productData'].find({'section': 'ШампанÑкое и игÑиÑÑое вино'}))1206 item_in_PD = [i for i in productData if i['id'] == product_id]1207 if item_in_PD:1208 item_in_PD_index = productData.index(item_in_PD[0])1209 for i in link_list:1210 item_in_PD[0]['links'].append(i)1211 Merger_DB['productData'].update({'_id': item_in_PD[0]['id']}, {'$set': item_in_PD[0]}, upsert=True)1212 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())1213 need_change = [i for i in champagne if i['link'] in link_list]1214 for i in need_change:1215 i['in_productData'] = True1216 Merger_DB['ШампанÑкое и игÑиÑÑое вино'].update({'_id': i['_id']}, {'$set': i}, upsert=True)1217 Merger_DB['link_list'].update({'_id': 'champagne_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1218 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())1219 write_file('champagne.json', champagne)1220 productData = list(Merger_DB['productData'].find())1221 write_file('productData.json', productData)1222 return redirect('/champagne_grouping_prove')1223 else:1224 if main_drink:1225 link_list.append(main_drink['link'])1226 product_id = take_article()1227 for i in link_list:1228 drink = [k for k in champagne if k['link'] == i][0]1229 ind = champagne.index(drink)1230 drink['identified'] = True1231 drink['product_id'] = product_id1232 if not ('id' in champagne[ind].keys()):1233 drink['id'] = take_article()1234 Merger_DB['ШампанÑкое и игÑиÑÑое вино'].update({'_id': drink['_id']}, {'$set': drink}, upsert=True)1235 Merger_DB['link_list'].update({'_id': 'champagne_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1236 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())1237 main_drink = [i for i in champagne if i['identified'] is False and not (i['link'] in skip_list)]1238 if main_drink:1239 main_drink = main_drink[0]1240 else:1241 skip_list = list(Merger_DB['skip_list'].find({'_id': 'champagne_skip_list'}))1242 if skip_list:1243 skip_list = skip_list[0]['skip_list']1244 if skip_list:1245 del skip_list[0]1246 main_drink = [i for i in champagne if i['identified'] is False and not (i['link'] in skip_list)]1247 if main_drink:1248 main_drink = main_drink[0]1249 Merger_DB['skip_list'].update({'_id': 'champagne_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1250 # saving data to files1251 champagne = list(Merger_DB['ШампанÑкое и игÑиÑÑое вино'].find())1252 write_file('champagne.json', champagne)1253 return redirect('/champagne_grouping_prove')1254 group_id = numpy.unique([i['product_id'] for i in result_list if 'product_id' in i.keys()])1255 groups = list()1256 products_with_id = [i for i in champagne if 'product_id' in i.keys()]1257 for i in group_id:1258 group = [k for k in products_with_id if k['product_id'] == i]1259 groups.append(group)1260 result_list = [i for i in result_list if not (i in group)]1261 # ÑиÑло неÑгÑÑппиÑованнÑÑ
напиÑков1262 undone = Merger_DB['ШампанÑкое и игÑиÑÑое вино'].count_documents({'identified': False})1263 # ÐомеÑа гÑÑпп в гÑÑппиÑовке1264 productData = list(Merger_DB['productData'].find({'section': 'ШампанÑкое и игÑиÑÑое вино'}))1265 new_nums = []1266 if groups:1267 # group_nums = numpy.unique([k[0]['product_id'] for k in groups if 'product_id' in k[0].keys()])1268 group_nums = numpy.unique([k[0]['product_id'] for k in groups if 'in_productData' in k[0].keys()])1269 group_nums = list(group_nums)1270 if group_nums:1271 print(group_nums)1272 for i in group_nums:1273 new_nums.append(productData.index([k for k in productData if k['id'] == i][0]) + 1)1274 new_group = []1275 for i in groups:1276 if 'in_productData' in i[0].keys():1277 new_group.append(i)1278 for i in groups:1279 if not (i in new_group):1280 new_group.append(i)1281 groups = new_group1282 return render_template('grouping_champagne.html', main_drink=main_drink, products=result_list, groups=groups, undone=undone, group_nums=new_nums)1283@app.route('/grouping_cognac/', methods=['GET', 'POST'])1284def grouping_cognac():1285 ip_address = request.remote_addr.replace('.', '')1286 if request.method == 'GET':1287 Merger_DB['link_list'].update({'_id': 'cognac_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1288 search = ''1289 result_list = []1290 cognac = list(Merger_DB['ÐонÑÑк'].find())1291 skip_list = list(Merger_DB['skip_list'].find({'_id': 'cognac_skip_list'}))1292 if skip_list:1293 skip_list = skip_list[0]['skip_list']1294 main_drink = [i for i in cognac if i['identified'] is False and not (i['link'] in skip_list)]1295 if main_drink:1296 main_drink = main_drink[0]1297 else:1298 if skip_list:1299 del skip_list[0]1300 main_drink = [i for i in cognac if i['identified'] is False and not (i['link'] in skip_list)]1301 if main_drink:1302 main_drink = main_drink[0]1303 Merger_DB['skip_list'].update({'_id': 'cognac_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1304 if "index" in request.form:1305 link = request.form['index']1306 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'cognac_link_list'}, {ip_address: {'$exists': True}}]}))1307 if link_list:1308 link_list = link_list[0][ip_address]1309 if link in link_list:1310 link_list.remove(link)1311 else:1312 link_list.append(link)1313 Merger_DB['link_list'].update({'_id': 'cognac_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1314 if 'add_to_group' in request.form:1315 article = request.form['add_to_group']1316 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'cognac_link_list'}, {ip_address: {'$exists': True}}]}))1317 if link_list:1318 link_list = link_list[0][ip_address]1319 if article in link_list:1320 link_list.remove(article)1321 else:1322 link_list.append(article)1323 Merger_DB['link_list'].update({'_id': 'cognac_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1324 if 'skip' in request.form:1325 Merger_DB['link_list'].update({'_id': 'cognac_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1326 skip_list = list(Merger_DB['skip_list'].find({'_id': 'cognac_skip_list'}))1327 if skip_list:1328 skip_list = skip_list[0]['skip_list']1329 if not (request.form['skip'] in skip_list):1330 skip_list.append(request.form['skip'])1331 main_drink = [i for i in cognac if i['identified'] is False and not (i['link'] in skip_list)]1332 if main_drink:1333 main_drink = main_drink[0]1334 else:1335 if skip_list:1336 del skip_list[0]1337 main_drink = [i for i in cognac if i['identified'] is False and not (i['link'] in skip_list)]1338 if main_drink:1339 main_drink = main_drink[0]1340 Merger_DB['skip_list'].update({'_id': 'cognac_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1341 if 'search' in request.form:1342 search = request.form['search']1343 result_list = [i for i in cognac if search.lower() in i['name'].lower() and not (i is main_drink)]1344 if 'saving' in request.form:1345 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'cognac_link_list'}, {ip_address: {'$exists': True}}]}))1346 if link_list:1347 link_list = link_list[0][ip_address]1348 match = [i for i in link_list if i.isdigit()]1349 if len(match) > 1:1350 flash('ÐÑибка: ÐÑ Ð¼Ð¾Ð¶ÐµÑе добавиÑÑ Ð½Ð°Ð¿Ð¸Ñок ÑолÑко в Ð¾Ð´Ð½Ñ Ð³ÑÑппÑ')1351 Merger_DB['link_list'].update({'_id': 'cognac_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1352 return redirect('/grouping_cognac')1353 elif len(match) == 1:1354 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'cognac_link_list'}, {ip_address: {'$exists': True}}]}))1355 if link_list:1356 link_list = link_list[0][ip_address]1357 link_list.remove(match[0])1358 if main_drink:1359 link_list.append(main_drink['link'])1360 Merger_DB['link_list'].update({'_id': 'cognac_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1361 product_id = match[0]1362 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'cognac_link_list'}, {ip_address: {'$exists': True}}]}))1363 if link_list:1364 link_list = link_list[0][ip_address]1365 for i in link_list:1366 drink = [k for k in cognac if k['link'] == i][0]1367 ind = cognac.index(drink)1368 drink['identified'] = True1369 drink['product_id'] = product_id1370 if not ('id' in cognac[ind].keys()):1371 drink['id'] = take_article()1372 Merger_DB['ÐонÑÑк'].update({'_id': drink['_id']}, {'$set': drink}, upsert=True)1373 cognac = list(Merger_DB['ÐонÑÑк'].find())1374 main_drink = [i for i in cognac if i['identified'] is False and not (i['link'] in skip_list)]1375 if main_drink:1376 main_drink = main_drink[0]1377 else:1378 skip_list = list(Merger_DB['skip_list'].find({'_id': 'cognac_skip_list'}))1379 if skip_list:1380 skip_list = skip_list[0]['skip_list']1381 if skip_list:1382 del skip_list[0]1383 main_drink = [i for i in cognac if i['identified'] is False and not (i['link'] in skip_list)]1384 if main_drink:1385 main_drink = main_drink[0]1386 Merger_DB['skip_list'].update({'_id': 'cognac_skip_list'}, {'$set': {'skip_list': skip_list}},1387 upsert=True)1388 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'cognac_link_list'}, {ip_address: {'$exists': True}}]}))1389 if link_list:1390 link_list = link_list[0][ip_address]1391 productData = list(Merger_DB['productData'].find({'section': 'ÐонÑÑк'}))1392 item_in_PD = [i for i in productData if i['id'] == product_id]1393 if item_in_PD:1394 item_in_PD_index = productData.index(item_in_PD[0])1395 for i in link_list:1396 item_in_PD[0]['links'].append(i)1397 Merger_DB['productData'].update({'_id': item_in_PD[0]['id']}, {'$set': item_in_PD[0]}, upsert=True)1398 cognac = list(Merger_DB['ÐонÑÑк'].find())1399 need_change = [i for i in cognac if i['link'] in link_list]1400 for i in need_change:1401 i['in_productData'] = True1402 Merger_DB['ÐонÑÑк'].update({'_id': i['_id']}, {'$set': i}, upsert=True)1403 Merger_DB['link_list'].update({'_id': 'cognac_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1404 # saving data to files1405 cognac = list(Merger_DB['ÐонÑÑк'].find())1406 write_file('cognac.json', cognac)1407 productData = list(Merger_DB['productData'].find())1408 write_file('productData.json', productData)1409 return redirect('/cognac_grouping_prove')1410 else:1411 if main_drink:1412 link_list.append(main_drink['link'])1413 product_id = take_article()1414 for i in link_list:1415 drink = [k for k in cognac if k['link'] == i][0]1416 ind = cognac.index(drink)1417 drink['identified'] = True1418 drink['product_id'] = product_id1419 if not ('id' in cognac[ind].keys()):1420 drink['id'] = take_article()1421 Merger_DB['ÐонÑÑк'].update({'_id': drink['_id']}, {'$set': drink}, upsert=True)1422 Merger_DB['link_list'].update({'_id': 'cognac_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1423 cognac = list(Merger_DB['ÐонÑÑк'].find())1424 main_drink = [i for i in cognac if i['identified'] is False and not (i['link'] in skip_list)]1425 if main_drink:1426 main_drink = main_drink[0]1427 else:1428 skip_list = list(Merger_DB['skip_list'].find({'_id': 'cognac_skip_list'}))1429 if skip_list:1430 skip_list = skip_list[0]['skip_list']1431 if skip_list:1432 del skip_list[0]1433 main_drink = [i for i in cognac if i['identified'] is False and not (i['link'] in skip_list)]1434 if main_drink:1435 main_drink = main_drink[0]1436 Merger_DB['skip_list'].update({'_id': 'cognac_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1437 # saving data to files1438 cognac = list(Merger_DB['ÐонÑÑк'].find())1439 write_file('cognac.json', cognac)1440 return redirect('/cognac_grouping_prove')1441 group_id = numpy.unique([i['product_id'] for i in result_list if 'product_id' in i.keys()])1442 groups = list()1443 products_with_id = [i for i in cognac if 'product_id' in i.keys()]1444 for i in group_id:1445 group = [k for k in products_with_id if k['product_id'] == i]1446 groups.append(group)1447 result_list = [i for i in result_list if not (i in group)]1448 # ÑиÑло неÑгÑÑппиÑованнÑÑ
напиÑков1449 undone = Merger_DB['ÐонÑÑк'].count_documents({'identified': False})1450 # ÐомеÑа гÑÑпп в гÑÑппиÑовке1451 productData = list(Merger_DB['productData'].find({'section': 'ÐонÑÑк'}))1452 new_nums = []1453 if groups:1454 # group_nums = numpy.unique([k[0]['product_id'] for k in groups if 'product_id' in k[0].keys()])1455 group_nums = numpy.unique([k[0]['product_id'] for k in groups if 'in_productData' in k[0].keys()])1456 group_nums = list(group_nums)1457 if group_nums:1458 for i in group_nums:1459 new_nums.append(productData.index([k for k in productData if k['id'] == i][0]) + 1)1460 new_group = []1461 for i in groups:1462 if 'in_productData' in i[0].keys():1463 new_group.append(i)1464 for i in groups:1465 if not (i in new_group):1466 new_group.append(i)1467 groups = new_group1468 return render_template('grouping_cognac.html', main_drink=main_drink, products=result_list, groups=groups, undone=undone, group_nums=new_nums)1469@app.route('/grouping_vodka/', methods=['GET', 'POST'])1470def grouping_vodka():1471 ip_address = request.remote_addr.replace('.', '')1472 if request.method == 'GET':1473 Merger_DB['link_list'].update({'_id': 'vodka_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1474 search = ''1475 result_list = []1476 vodka = list(Merger_DB['Ðодка'].find())1477 skip_list = list(Merger_DB['skip_list'].find({'_id': 'vodka_skip_list'}))1478 if skip_list:1479 skip_list = skip_list[0]['skip_list']1480 main_drink = [i for i in vodka if i['identified'] is False and not (i['link'] in skip_list)]1481 if main_drink:1482 main_drink = main_drink[0]1483 else:1484 if skip_list:1485 del skip_list[0]1486 main_drink = [i for i in vodka if i['identified'] is False and not (i['link'] in skip_list)]1487 if main_drink:1488 main_drink = main_drink[0]1489 Merger_DB['skip_list'].update({'_id': 'vodka_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1490 if "index" in request.form:1491 link = request.form['index']1492 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'vodka_link_list'}, {ip_address: {'$exists': True}}]}))1493 if link_list:1494 link_list = link_list[0][ip_address]1495 if link in link_list:1496 link_list.remove(link)1497 else:1498 link_list.append(link)1499 Merger_DB['link_list'].update({'_id': 'vodka_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1500 if 'add_to_group' in request.form:1501 article = request.form['add_to_group']1502 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'vodka_link_list'}, {ip_address: {'$exists': True}}]}))1503 if link_list:1504 link_list = link_list[0][ip_address]1505 if article in link_list:1506 link_list.remove(article)1507 else:1508 link_list.append(article)1509 Merger_DB['link_list'].update({'_id': 'vodka_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1510 if 'skip' in request.form:1511 Merger_DB['link_list'].update({'_id': 'vodka_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1512 skip_list = list(Merger_DB['skip_list'].find({'_id': 'vodka_skip_list'}))1513 if skip_list:1514 skip_list = skip_list[0]['skip_list']1515 if not (request.form['skip'] in skip_list):1516 skip_list.append(request.form['skip'])1517 main_drink = [i for i in vodka if i['identified'] is False and not (i['link'] in skip_list)]1518 if main_drink:1519 main_drink = main_drink[0]1520 else:1521 if skip_list:1522 del skip_list[0]1523 main_drink = [i for i in vodka if i['identified'] is False and not (i['link'] in skip_list)]1524 if main_drink:1525 main_drink = main_drink[0]1526 Merger_DB['skip_list'].update({'_id': 'vodka_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1527 if 'search' in request.form:1528 search = request.form['search']1529 result_list = [i for i in vodka if search.lower() in i['name'].lower() and not (i is main_drink)]1530 if 'saving' in request.form:1531 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'vodka_link_list'}, {ip_address: {'$exists': True}}]}))1532 if link_list:1533 link_list = link_list[0][ip_address]1534 match = [i for i in link_list if i.isdigit()]1535 if len(match) > 1:1536 flash('ÐÑибка: ÐÑ Ð¼Ð¾Ð¶ÐµÑе добавиÑÑ Ð½Ð°Ð¿Ð¸Ñок ÑолÑко в Ð¾Ð´Ð½Ñ Ð³ÑÑппÑ')1537 Merger_DB['link_list'].update({'_id': 'vodka_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1538 return redirect('/grouping_vodka')1539 elif len(match) == 1:1540 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'vodka_link_list'}, {ip_address: {'$exists': True}}]}))1541 if link_list:1542 link_list = link_list[0][ip_address]1543 link_list.remove(match[0])1544 if main_drink:1545 link_list.append(main_drink['link'])1546 Merger_DB['link_list'].update({'_id': 'vodka_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1547 product_id = match[0]1548 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'vodka_link_list'}, {ip_address: {'$exists': True}}]}))1549 if link_list:1550 link_list = link_list[0][ip_address]1551 for i in link_list:1552 drink = [k for k in vodka if k['link'] == i][0]1553 ind = vodka.index(drink)1554 drink['identified'] = True1555 drink['product_id'] = product_id1556 if not ('id' in vodka[ind].keys()):1557 drink['id'] = take_article()1558 Merger_DB['Ðодка'].update({'_id': drink['_id']}, {'$set': drink}, upsert=True)1559 vodka = list(Merger_DB['Ðодка'].find())1560 main_drink = [i for i in vodka if i['identified'] is False and not (i['link'] in skip_list)]1561 if main_drink:1562 main_drink = main_drink[0]1563 else:1564 skip_list = list(Merger_DB['skip_list'].find({'_id': 'vodka_skip_list'}))1565 if skip_list:1566 skip_list = skip_list[0]['skip_list']1567 if skip_list:1568 del skip_list[0]1569 main_drink = [i for i in vodka if i['identified'] is False and not (i['link'] in skip_list)]1570 if main_drink:1571 main_drink = main_drink[0]1572 Merger_DB['skip_list'].update({'_id': 'vodka_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1573 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'vodka_link_list'}, {ip_address: {'$exists': True}}]}))1574 if link_list:1575 link_list = link_list[0][ip_address]1576 productData = list(Merger_DB['productData'].find({'section': 'Ðодка'}))1577 item_in_PD = [i for i in productData if i['id'] == product_id]1578 if item_in_PD:1579 item_in_PD_index = productData.index(item_in_PD[0])1580 for i in link_list:1581 item_in_PD[0]['links'].append(i)1582 Merger_DB['productData'].update({'_id': item_in_PD[0]['id']}, {'$set': item_in_PD[0]}, upsert=True)1583 vodka = list(Merger_DB['Ðодка'].find())1584 need_change = [i for i in vodka if i['link'] in link_list]1585 for i in need_change:1586 i['in_productData'] = True1587 Merger_DB['Ðодка'].update({'_id': i['_id']}, {'$set': i}, upsert=True)1588 Merger_DB['link_list'].update({'_id': 'vodka_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1589 # saving data to files1590 vodka = list(Merger_DB['Ðодка'].find())1591 write_file('vodka.json', vodka)1592 productData = list(Merger_DB['productData'].find())1593 write_file('productData.json', productData)1594 return redirect('/vodka_grouping_prove')1595 else:1596 if main_drink:1597 link_list.append(main_drink['link'])1598 product_id = take_article()1599 write_file('vodka_link_list.json', [])1600 for i in link_list:1601 drink = [k for k in vodka if k['link'] == i][0]1602 ind = vodka.index(drink)1603 drink['identified'] = True1604 drink['product_id'] = product_id1605 if not('id' in vodka[ind].keys()):1606 drink['id'] = take_article()1607 Merger_DB['Ðодка'].update({'_id': drink['_id']}, {'$set': drink}, upsert=True)1608 Merger_DB['link_list'].update({'_id': 'vodka_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1609 vodka = list(Merger_DB['Ðодка'].find())1610 main_drink = [i for i in vodka if i['identified'] is False and not (i['link'] in skip_list)]1611 if main_drink:1612 main_drink = main_drink[0]1613 else:1614 skip_list = list(Merger_DB['skip_list'].find({'_id': 'vodka_skip_list'}))1615 if skip_list:1616 skip_list = skip_list[0]['skip_list']1617 if skip_list:1618 del skip_list[0]1619 main_drink = [i for i in vodka if i['identified'] is False and not (i['link'][0] in skip_list)]1620 if main_drink:1621 main_drink = main_drink[0]1622 Merger_DB['skip_list'].update({'_id': 'vodka_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1623 # saving data to files1624 vodka = list(Merger_DB['Ðодка'].find())1625 write_file('vodka.json', vodka)1626 return redirect('/vodka_grouping_prove')1627 group_id = numpy.unique([i['product_id'] for i in result_list if 'product_id' in i.keys()])1628 groups = list()1629 products_with_id = [i for i in vodka if 'product_id' in i.keys()]1630 for i in group_id:1631 group = [k for k in products_with_id if k['product_id'] == i]1632 groups.append(group)1633 result_list = [i for i in result_list if not (i in group)]1634 1635 # ÑиÑло неÑгÑÑппиÑованнÑÑ
напиÑков 1636 undone = Merger_DB['Ðодка'].count_documents({'identified': False})1637 # ÐомеÑа гÑÑпп в гÑÑппиÑовке1638 productData = list(Merger_DB['productData'].find({'section': 'Ðодка'}))1639 new_nums = []1640 if groups:1641 # group_nums = numpy.unique([k[0]['product_id'] for k in groups if 'product_id' in k[0].keys()])1642 group_nums = numpy.unique([k[0]['product_id'] for k in groups if 'in_productData' in k[0].keys()])1643 group_nums = list(group_nums)1644 if group_nums:1645 for i in group_nums:1646 new_nums.append(productData.index([k for k in productData if k['id'] == i][0]) + 1)1647 new_group = []1648 for i in groups:1649 if 'in_productData' in i[0].keys():1650 new_group.append(i)1651 for i in groups:1652 if not (i in new_group):1653 new_group.append(i)1654 groups = new_group1655 return render_template('grouping_vodka.html', main_drink=main_drink, products=result_list, groups=groups, undone=undone, group_nums=new_nums)1656@app.route('/grouping_whiskey/', methods=['GET', 'POST'])1657def grouping_whiskey():1658 # update_data = read_file('whiskey_update.json')1659 # if update_data:1660 # for i in update_data:1661 # Merger_DB['ÐиÑки'].update({'_id': i['_id']}, {'$set': i}, upsert=True)1662 ip_address = request.remote_addr.replace('.', '')1663 if request.method == 'GET':1664 Merger_DB['link_list'].update({'_id': 'whiskey_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1665 search = ''1666 result_list = []1667 whiskey = list(Merger_DB['ÐиÑки'].find())1668 skip_list = list(Merger_DB['skip_list'].find({'_id': 'whiskey_skip_list'}))1669 if skip_list:1670 skip_list = skip_list[0]['skip_list']1671 main_drink = [i for i in whiskey if i['identified'] is False and not (i['link'] in skip_list)]1672 if main_drink:1673 main_drink = main_drink[0]1674 else:1675 if skip_list:1676 del skip_list[0]1677 main_drink = [i for i in whiskey if i['identified'] is False and not (i['link'] in skip_list)]1678 if main_drink:1679 main_drink = main_drink[0]1680 Merger_DB['skip_list'].update({'_id': 'whiskey_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1681 if "index" in request.form:1682 link = request.form['index']1683 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'whiskey_link_list'}, {ip_address: {'$exists': True}}]}))1684 if link_list:1685 link_list = link_list[0][ip_address]1686 if link in link_list:1687 link_list.remove(link)1688 else:1689 link_list.append(link)1690 Merger_DB['link_list'].update({'_id': 'whiskey_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1691 if 'add_to_group' in request.form:1692 article = request.form['add_to_group']1693 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'whiskey_link_list'}, {ip_address: {'$exists': True}}]}))1694 if link_list:1695 link_list = link_list[0][ip_address]1696 if article in link_list:1697 link_list.remove(article)1698 else:1699 link_list.append(article)1700 Merger_DB['link_list'].update({'_id': 'whiskey_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1701 if 'skip' in request.form:1702 Merger_DB['link_list'].update({'_id': 'whiskey_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1703 skip_list = list(Merger_DB['skip_list'].find({'_id': 'whiskey_skip_list'}))1704 if skip_list:1705 skip_list = skip_list[0]['skip_list']1706 if not (request.form['skip'] in skip_list):1707 skip_list.append(request.form['skip'])1708 main_drink = [i for i in whiskey if i['identified'] is False and not (i['link'] in skip_list)]1709 if main_drink:1710 main_drink = main_drink[0]1711 else:1712 if skip_list:1713 del skip_list[0]1714 main_drink = [i for i in whiskey if i['identified'] is False and not (i['link'] in skip_list)]1715 if main_drink:1716 main_drink = main_drink[0]1717 Merger_DB['skip_list'].update({'_id': 'whiskey_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1718 if 'search' in request.form:1719 search = request.form['search']1720 result_list = [i for i in whiskey if search.lower() in i['name'].lower() and not (i is main_drink)]1721 if 'saving' in request.form:1722 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'whiskey_link_list'}, {ip_address: {'$exists': True}}]}))1723 if link_list:1724 link_list = link_list[0][ip_address]1725 match = [i for i in link_list if i.isdigit()]1726 if len(match) > 1:1727 flash('ÐÑибка: ÐÑ Ð¼Ð¾Ð¶ÐµÑе добавиÑÑ Ð½Ð°Ð¿Ð¸Ñок ÑолÑко в Ð¾Ð´Ð½Ñ Ð³ÑÑппÑ')1728 Merger_DB['link_list'].update({'_id': 'whiskey_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1729 return redirect('/grouping_whiskey')1730 elif len(match) == 1:1731 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'whiskey_link_list'}, {ip_address: {'$exists': True}}]}))1732 if link_list:1733 link_list = link_list[0][ip_address]1734 link_list.remove(match[0])1735 if main_drink:1736 link_list.append(main_drink['link'])1737 Merger_DB['link_list'].update({'_id': 'whiskey_link_list'}, {'$set': {ip_address: link_list}}, upsert=True)1738 product_id = match[0]1739 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'whiskey_link_list'}, {ip_address: {'$exists': True}}]}))1740 if link_list:1741 link_list = link_list[0][ip_address]1742 for i in link_list:1743 drink = [k for k in whiskey if k['link'] == i][0]1744 ind = whiskey.index(drink)1745 drink['identified'] = True1746 drink['product_id'] = product_id1747 if not ('id' in whiskey[ind].keys()):1748 drink['id'] = take_article()1749 Merger_DB['ÐиÑки'].update({'_id': drink['_id']}, {'$set': drink}, upsert=True)1750 whiskey = list(Merger_DB['ÐиÑки'].find())1751 main_drink = [i for i in whiskey if i['identified'] is False and not (i['link'] in skip_list)]1752 if main_drink:1753 main_drink = main_drink[0]1754 else:1755 skip_list = list(Merger_DB['skip_list'].find({'_id': 'whiskey_skip_list'}))1756 if skip_list:1757 skip_list = skip_list[0]['skip_list']1758 if skip_list:1759 del skip_list[0]1760 main_drink = [i for i in whiskey if i['identified'] is False and not (i['link'] in skip_list)]1761 if main_drink:1762 main_drink = main_drink[0]1763 Merger_DB['skip_list'].update({'_id': 'whiskey_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1764 link_list = list(Merger_DB['link_list'].find({'$and': [{'_id': 'whiskey_link_list'}, {ip_address: {'$exists': True}}]}))1765 if link_list:1766 link_list = link_list[0][ip_address]1767 productData = list(Merger_DB['productData'].find({'section': 'ÐиÑки'}))1768 item_in_PD = [i for i in productData if i['id'] == product_id]1769 if item_in_PD:1770 item_in_PD_index = productData.index(item_in_PD[0])1771 for i in link_list:1772 item_in_PD[0]['links'].append(i)1773 Merger_DB['productData'].update({'_id': item_in_PD[0]['id']}, {'$set': item_in_PD[0]}, upsert=True)1774 whiskey = list(Merger_DB['ÐиÑки'].find())1775 need_change = [i for i in whiskey if i['link'] in link_list]1776 for i in need_change:1777 i['in_productData'] = True1778 Merger_DB['ÐиÑки'].update({'_id': i['_id']}, {'$set': i}, upsert=True)1779 Merger_DB['link_list'].update({'_id': 'whiskey_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1780 # saving data to files1781 whiskey = list(Merger_DB['ÐиÑки'].find())1782 write_file('whiskey.json', whiskey)1783 productData = list(Merger_DB['productData'].find())1784 write_file('productData.json', productData)1785 return redirect('/whiskey_grouping_prove')1786 else:1787 if main_drink:1788 link_list.append(main_drink['link'])1789 product_id = take_article()1790 for i in link_list:1791 drink = [k for k in whiskey if k['link'] == i][0]1792 ind = whiskey.index(drink)1793 drink['identified'] = True1794 drink['product_id'] = product_id1795 if not('id' in whiskey[ind].keys()):1796 drink['id'] = take_article()1797 Merger_DB['ÐиÑки'].update({'_id': drink['_id']}, {'$set': drink}, upsert=True)1798 Merger_DB['link_list'].update({'_id': 'whiskey_link_list'}, {'$unset': {ip_address: 1}}, upsert=True)1799 whiskey = list(Merger_DB['ÐиÑки'].find())1800 main_drink = [i for i in whiskey if i['identified'] is False and not (i['link'] in skip_list)]1801 if main_drink:1802 main_drink = main_drink[0]1803 else:1804 skip_list = list(Merger_DB['skip_list'].find({'_id': 'whiskey_skip_list'}))1805 if skip_list:1806 skip_list = skip_list[0]['skip_list']1807 if skip_list:1808 del skip_list[0]1809 main_drink = [i for i in whiskey if i['identified'] is False and not (i['link'] in skip_list)]1810 if main_drink:1811 main_drink = main_drink[0]1812 Merger_DB['skip_list'].update({'_id': 'whiskey_skip_list'}, {'$set': {'skip_list': skip_list}}, upsert=True)1813 # saving data to files1814 whiskey = list(Merger_DB['ÐиÑки'].find())1815 write_file('whiskey.json', whiskey)1816 return redirect('/whiskey_grouping_prove')1817 # group_id = set([i['product_id'] for i in result_list if 'product_id' in i.keys()])1818 group_id = numpy.unique([i['product_id'] for i in result_list if 'product_id' in i.keys()])1819 groups = list()1820 products_with_id = [i for i in whiskey if 'product_id' in i.keys()]1821 for i in group_id:1822 group = [k for k in products_with_id if k['product_id'] == i]1823 groups.append(group)1824 result_list = [i for i in result_list if not (i in group)]1825 1826 # ÑиÑло неÑгÑÑппиÑованнÑÑ
напиÑков1827 undone = Merger_DB['ÐиÑки'].count_documents({'identified': False})1828 # ÐомеÑа гÑÑпп в гÑÑппиÑовке1829 productData = list(Merger_DB['productData'].find({'section': 'ÐиÑки'}))1830 new_nums = []1831 if groups:1832 # group_nums = numpy.unique([k[0]['product_id'] for k in groups if 'product_id' in k[0].keys()])1833 group_nums = numpy.unique([k[0]['product_id'] for k in groups if 'in_productData' in k[0].keys()])1834 group_nums = list(group_nums)1835 if group_nums:1836 for i in group_nums:1837 new_nums.append(productData.index([k for k in productData if k['id'] == i][0]) + 1)1838 new_group = []1839 for i in groups:1840 if 'in_productData' in i[0].keys():1841 new_group.append(i)1842 for i in groups:1843 if not (i in new_group):1844 new_group.append(i)1845 groups = new_group1846 return render_template('grouping_whiskey.html', main_drink=main_drink, products=result_list, groups=groups, undone=undone, group_nums=new_nums)1847def read_file(file_name):1848 with open(file_name) as f:1849 file = f.read()1850 file = json.loads(file)1851 f.close()1852 return file1853# def read_file(file_name):1854# new_name = file_name[:file_name.index('.json')] + '_dont_touch.json'1855# start_time = time.time()1856# while True:1857# if time.time() - start_time > 5:1858# os.rename(new_name, file_name)1859# try:1860# os.rename(file_name, new_name)1861# with open(new_name) as f:1862# file = f.read()1863# file = json.loads(file)1864# f.close()1865# os.rename(new_name, file_name)1866# return file1867# except:1868# time.sleep(0.5)1869def write_file(file_name, data):1870 with open(file_name, 'w') as f:1871 json.dump(data, f, ensure_ascii=False, indent=2)1872 f.close()1873 return1874# def write_file(file_name, data):1875# new_name = file_name[:file_name.index('.json')] + '_dont_touch.json'1876# os.rename(file_name, new_name)1877# with open(new_name, 'w') as f:1878# json.dump(data, f, ensure_ascii=False, indent=2)1879# f.close()1880# while True:1881# try:1882# with open(new_name) as f:1883# file = f.read()1884# file = json.loads(file)1885# f.close()1886# while True:1887# if len(file) == len(data):1888# break1889# else:1890# continue1891# break1892# except:1893# time.sleep(0.5)1894# os.rename(new_name, file_name)1895# return1896# def take_article():1897# with open('articles.txt', 'r') as f:1898# doc = f.read()1899# num = doc.split('\n')1900# del num[-1]1901# article = num[-1]1902# with open('articles.txt', 'w') as f:1903# doc = doc.replace(article + '\n', '')1904# f.write(doc)1905# f.close()1906# return article1907def take_article():1908 1909 while True:1910 try:1911 os.rename('articles.txt', 'articles_dont_touch.txt')1912 with open('articles_dont_touch.txt', 'r') as f:1913 doc = f.read()1914 num = doc.split('\n')1915 del num[-1]1916 article = num[-1]1917 f.close()1918 with open('articles_dont_touch.txt', 'w') as f:1919 doc = doc.replace(article + '\n', '')1920 f.write(doc)1921 f.close()1922 os.rename('articles_dont_touch.txt', 'articles.txt')1923 return article1924 except:1925 time.sleep(0.5)1926if __name__ == '__main__':1927 app.run(debug=True)1928 # from waitress import serve...
window.py
Source:window.py
1import os.path2from PyQt5.QtCore import Qt, QEvent, QPoint, QTimer3from PyQt5.QtWidgets import QMainWindow, QWidget, QGridLayout, QLabel, QHBoxLayout, QRadioButton, \4 QButtonGroup, QVBoxLayout, QComboBox, QFrame, QMenu, QAction5from PyQt5.QtGui import QIcon, QPixmap, QBrush, QPalette, QEnterEvent, QMouseEvent6import config7import core.contacts8import gui9global ignore_mouse_press_events, show_status, chat_list_changed10ignore_mouse_press_events: bool = False11show_group: int = 0 # Defaults to Everyone12show_status = config.STATUS_ALL13chat_list_changed: bool = True14class StatusSelectWidget(QWidget):15 def __init__(self):16 super().__init__()17 self.layout = QHBoxLayout()18 self.status = QButtonGroup()19 self.status_all = QRadioButton('All')20 self.status_all.setChecked(True)21 self.status_online = QRadioButton('Online')22 self.status_offline = QRadioButton('Offline')23 self.status_buttons = [self.status_all, self.status_online, self.status_offline]24 self.status.buttonToggled.connect(self.button_toggled)25 for button in self.status_buttons:26 self.status.addButton(button)27 self.layout.addWidget(button)28 self.setLayout(self.layout)29 def button_toggled(self, button: QRadioButton, checked: bool):30 if checked:31 global show_status, chat_list_changed32 chat_list_changed = True33 match button:34 case self.status_all:35 show_status = config.STATUS_ALL36 case self.status_online:37 show_status = config.STATUS_ONLINE38 case self.status_offline:39 show_status = config.STATUS_OFFLINE40class GroupSelectWidget(QWidget):41 def __init__(self):42 super().__init__()43 self.layout = QGridLayout()44 self.layout.setContentsMargins(6, 3, 0, 0)45 self.items = core.contacts.groups46 self.item_actions = {item: 'action' for item in self.items}47 self.select = QComboBox()48 self.select.addItems(self.items)49 self.select.setCurrentIndex(0)50 self.select.currentIndexChanged.connect(self.index_changed)51 self.layout.addWidget(self.select)52 self.setLayout(self.layout)53 @staticmethod54 def index_changed(index: int):55 global chat_list_changed, show_group56 chat_list_changed = True57 show_group = index58class ChatListItem(QFrame):59 def __init__(self, item):60 super().__init__()61 self.item = item62 self.id = item['id']63 self.position = item['position']64 self.layout = QHBoxLayout()65 self.layout.setContentsMargins(6, 6, 6, 6)66 self.setCursor(Qt.PointingHandCursor)67 icon = QLabel('')68 icon.setPixmap(item['icon'])69 self.layout.addWidget(icon)70 name = QLabel(item['name'])71 self.layout.addWidget(name)72 message = QLabel(item['message'])73 self.layout.addWidget(message)74 self.setLayout(self.layout)75 self.enterEvent = self.mouse_enter76 self.leaveEvent = self.mouse_leave77 self.mousePressEvent = self.mouse_pressed78 self.setContextMenuPolicy(Qt.CustomContextMenu)79 self.customContextMenuRequested.connect(self.show_context_menu)80 def mouse_enter(self, event: QEnterEvent):81 self.setStyleSheet('QFrame {background-color: rgba(255, 255, 255, 0.4);}'82 'QLabel {background-color: rgba(255, 255, 255, 0);}')83 return QWidget.enterEvent(self, event)84 def mouse_leave(self, event: QEvent):85 self.setStyleSheet('QFrame {background-color: rgba(255, 255, 255, 0);}')86 return QWidget.leaveEvent(self, event)87 def mouse_pressed(self, event: QMouseEvent):88 if event.button() == Qt.LeftButton:89 global ignore_mouse_press_events90 if not ignore_mouse_press_events:91 print('left pressed')92 else:93 ignore_mouse_press_events = False94 elif event.button() == Qt.RightButton:95 self.show_context_menu(event.globalPos())96 return QFrame.mousePressEvent(self, event)97 def show_context_menu(self, point: QPoint):98 context_menu = QMenu()99 profile = QAction('Open Profile')100 context_menu.addAction(profile)101 context_menu.addSeparator()102 dialog = QAction('New Dialog')103 context_menu.addAction(dialog)104 clear = QAction('Clear Dialog')105 context_menu.addAction(clear)106 context_menu.addSeparator()107 remove = QAction('Remove from Buddies')108 context_menu.addAction(remove)109 block = QAction('Remove and Block')110 context_menu.addAction(block)111 self.setCursor(Qt.ArrowCursor)112 action = context_menu.exec_(point)113 # After mouse clicked114 self.setCursor(Qt.PointingHandCursor)115 self.setStyleSheet('QFrame {background-color: rgba(255, 255, 255, 0);}')116 # Clicked outside117 if action is None:118 global ignore_mouse_press_events119 ignore_mouse_press_events = True120class ChatListWidget(QWidget):121 def __init__(self):122 super().__init__()123 self.layout = QVBoxLayout()124 self.layout.setContentsMargins(0, 0, 0, 0)125 self.layout.setSpacing(0)126 self.widgets = []127 self.ids = []128 global show_group, show_status129 self.show_group = show_group130 self.show_status = show_status131 self.setLayout(self.layout)132 def insert(self, position, widget):133 # Found - show hidden widget134 try:135 widget_index = self.widgets.index(widget)136 self.widgets[widget_index].setVisible(True)137 # Not found - add widget138 except ValueError:139 self.widgets.insert(position, widget)140 self.ids.append(widget.id)141 self.layout.insertWidget(position, widget)142 def remove(self, item_id):143 for widget in self.widgets:144 if widget['id'] == item_id:145 widget.setVisible(False)146 def clear(self):147 for widget in self.widgets:148 self.layout.removeWidget(widget)149 widget.setVisible(False)150 self.widgets = []151 self.ids = []152class ChatListPanel(QMainWindow):153 def __init__(self, parent):154 super().__init__()155 self.main_window = parent156 self.toolbar = gui.menu.Toolbar(self)157 self.addToolBar(self.toolbar)158 self.setMaximumWidth(config.Gui.CHAT_LIST_MAX_WIDTH)159 self.timer = QTimer(self)160 self.timer.timeout.connect(self.timeout)161 self.timer.start(config.Gui.chat_list_update_ms)162 self.background_pixmap = QPixmap(config.Gui.BACKGROUND_CHAT_LIST).scaled(self.size(), Qt.IgnoreAspectRatio)163 self.background_brush = QBrush(self.background_pixmap)164 self.background_palette = QPalette()165 self.background_palette.setBrush(QPalette.Background, self.background_brush)166 self.setPalette(self.background_palette)167 self.setAutoFillBackground(True)168 self.chat_list_widget = QWidget()169 self.chat_list_layout = QVBoxLayout()170 self.chat_list_layout.setContentsMargins(0, 0, 0, 0)171 self.chat_list_layout.setSpacing(0)172 self.chat_list_layout.setAlignment(Qt.AlignTop)173 self.select_widget = QWidget()174 self.select_layout = QHBoxLayout()175 self.select_layout.setContentsMargins(0, 0, 0, 0)176 self.select_layout.addWidget(GroupSelectWidget())177 self.select_layout.addWidget(StatusSelectWidget())178 self.select_widget.setLayout(self.select_layout)179 self.chat_list_layout.addWidget(self.select_widget)180 self.list_widget = ChatListWidget()181 self.buddies = []182 self.item_list = []183 self.set_list()184 self.chat_list_layout.addWidget(self.list_widget)185 self.chat_list_widget.setLayout(self.chat_list_layout)186 self.setCentralWidget(self.chat_list_widget)187 def set_list(self, status: int = config.STATUS_ALL):188 global chat_list_changed189 if not chat_list_changed:190 return191 chat_list_changed = False192 global show_group, show_status193 # If group select option changed194 if not self.list_widget.show_group == show_group:195 self.list_widget.clear()196 self.list_widget.show_group = show_group197 # If status radio button changed (and group option is the same)198 if not self.list_widget.show_status == show_status:199 self.list_widget.clear()200 self.list_widget.show_status = show_status201 self.buddies = core.contacts.get_buddies(group=show_group, status=status)202 for buddy in self.buddies:203 if not buddy['id'] in self.list_widget.ids:204 list_item = ChatListItem(buddy)205 self.list_widget.insert(buddy['position'], list_item)206 self.list_widget.setLayout(self.list_widget.layout)207 def timeout(self) -> None:208 global show_status, chat_list_changed209 if chat_list_changed:210 self.set_list(show_status)211class MessageListItem(QFrame):212 def __init__(self, message):213 super().__init__()214 self.layout = QHBoxLayout()215 self.label = QLabel(message)216 self.layout.addWidget(self.label)217 self.setLayout(self.layout)218class MessageListWidget(QWidget):219 def __init__(self):220 super().__init__()221 self.layout = QVBoxLayout()222 self.timer = QTimer(self)223 self.timer.start(100)224 self.label = QLabel('No messages yet.')225 self.layout.addWidget(self.label)226 self.setLayout(self.layout)227 self.show_messages('1')228 def show_messages(self, buddy_id):229 self.label.setVisible(False)230 for message in core.contacts.get_messages(buddy_id):231 self.layout.addWidget(MessageListItem(message))232class MessageListPanel(QWidget):233 def __init__(self):234 super().__init__()235 self.setMinimumWidth(config.Gui.MESSAGE_LIST_MIN_WIDTH)236 self.background_pixmap = QPixmap(config.Gui.BACKGROUND_MESSAGE_LIST).scaled(self.size(), Qt.IgnoreAspectRatio)237 self.background_brush = QBrush(self.background_pixmap)238 self.background_palette = QPalette()239 self.background_palette.setBrush(QPalette.Background, self.background_brush)240 self.setPalette(self.background_palette)241 self.setAutoFillBackground(True)242 self.layout = QVBoxLayout()243 self.layout.setSpacing(0)244 self.message_list_widget = MessageListWidget()245 self.layout.addWidget(self.message_list_widget)246 self.setLayout(self.layout)247class MainWindow(QMainWindow):248 def __init__(self):249 super().__init__()250 self.setWindowTitle(config.App.TITLE)251 self.setMinimumSize(config.Gui.WINDOW_MIN_SIZE)252 self.setWindowIcon(QIcon(config.Gui.ICON_APP))253 self.menu = gui.menu.Menubar(self)254 self.chat_list_panel = ChatListPanel(self)255 self.message_list_panel = MessageListPanel()256 # Insert toolbar menu show/hide action before status bar action257 self.menu.view.insertAction(self.menu.view_status_bar, self.chat_list_panel.toolbar.toggle_view)258 self.setMenuBar(self.menu)259 self.statusbar = gui.menu.StatusBar()260 self.setStatusBar(self.statusbar)261 status_pixmap = QPixmap(os.path.join(config.App.ICON_DIR, 'disconnected.png')262 ).scaled(config.Gui.statusbar_icon_size)263 self.status_label = QLabel('Status: Disconnected')264 self.status_icon = QLabel('')265 self.status_icon.setPixmap(status_pixmap)266 self.status_icon.setToolTip(self.status_label.text())267 self.statusbar.addPermanentWidget(self.status_label)268 self.statusbar.addPermanentWidget(self.status_icon)269 self.central_widget = QWidget()270 self.central_layout = QHBoxLayout()271 self.central_layout.setSpacing(0)272 self.central_layout.setContentsMargins(0, 0, 0, 0)273 self.central_layout.addWidget(self.chat_list_panel)274 self.central_layout.addWidget(self.message_list_panel)275 self.central_widget.setLayout(self.central_layout)...
components.py
Source:components.py
1from django_component import Library, Component2register = Library()3@register.component4class Message(Component):5 template = "base_components/message.html"6@register.component7class Nav_link(Component):8 template = "base_components/nav_link.html"9#Show_group10@register.component11class Sidebar(Component):12 template = "show_group/sidebar.html"13@register.component14class Meetings(Component):15 template = "show_group/meetings.html"16@register.component17class Notes(Component):18 template = "show_group/notes/notes.html"19@register.component20class Comments(Component):21 template = "show_group/notes/comments.html"22@register.component23class Vote_comment_btn(Component):24 template = "show_group/notes/vote_comment_btn.html"25@register.component26class Vote_note_btn(Component):27 template = "show_group/notes/vote_note_btn.html"28@register.component29class Members(Component):30 template = "show_group/members.html"31#Forms32@register.component33class Form_field(Component):34 template = "base_components/forms/form_field.html"35@register.component36class Form_file(Component):37 template = "base_components/forms/form_file.html"38@register.component39class Form_error(Component):40 template = "base_components/forms/form_error.html"41@register.component42class Form_btn(Component):43 template = "base_components/forms/form_btn.html"44@register.component45class Group_buttons(Component):46 template = "base_components/group_buttons.html"47# CARDS48@register.component49class Card_child(Component):50 template = "base_components/cards/card_child.html"51@register.component52class Card_parent(Component):53 template = "base_components/cards/card_parent.html"54@register.component55class Card_user(Component):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!