Commit e0f0da64 by lichenggang

init

parents
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (tornado_api_server) (2)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/update_cate.iml" filepath="$PROJECT_DIR$/.idea/update_cate.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="bdc1212b-a67e-465a-8c9c-03055b5d227f" name="Default Changelist" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="CoverageDataManager">
<SUITE FILE_PATH="coverage/update_cate$update_scrip.coverage" NAME="update_scrip Coverage Results" MODIFIED="1554371665991" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/update_cate$cate_stock.coverage" NAME="cate_stock Coverage Results" MODIFIED="1554366485583" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/platform/element14" />
<SUITE FILE_PATH="coverage/update_cate$clean.coverage" NAME="clean Coverage Results" MODIFIED="1554370790353" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/update_cate$updateopera.coverage" NAME="updateopera Coverage Results" MODIFIED="1554371660616" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/plat/element14/cate_stock.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="58">
<caret line="28" column="82" lean-forward="true" selection-start-line="28" selection-start-column="82" selection-end-line="28" selection-end-column="98" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/plat/szlc/cate_stock.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="329">
<caret line="104" column="12" lean-forward="true" selection-start-line="104" selection-start-column="12" selection-end-line="104" selection-end-column="32" />
<folding>
<element signature="e#154#718#0" />
<element signature="e#760#2320#0" />
<element signature="e#1304#2298#0" />
<element signature="e#1850#2266#0" />
<element signature="e#2847#2922#0" />
<element signature="e#2882#2922#0" />
<element signature="e#2966#3053#0" />
<element signature="e#2996#3053#0" />
<element signature="e#3986#4126#0" />
<element signature="e#4009#4110#0" />
<element signature="e#4035#4110#0" />
<element signature="e#4070#4110#0" />
<element signature="e#4222#4910#0" />
<element signature="e#4251#4881#0" />
<element signature="e#4291#4881#0" />
<element signature="e#4331#4550#0" />
<element signature="e#4593#4881#0" />
<element signature="e#4599#4755#0" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/plat/chip1stop/cate.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="609">
<caret line="84" column="34" lean-forward="true" selection-start-line="84" selection-start-column="34" selection-end-line="84" selection-end-column="54" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/updateopera.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="462">
<caret line="22" column="62" lean-forward="true" selection-start-line="22" selection-start-column="62" selection-end-line="22" selection-end-column="62" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/clean.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret selection-end-line="14" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/update_scrip.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="231">
<caret line="11" lean-forward="true" selection-start-line="11" selection-end-line="11" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/utils/mysqlopera.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="42">
<caret line="2" lean-forward="true" selection-start-line="2" selection-end-line="2" />
<folding>
<element signature="e#45#55#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>COB LED底座-供电</find>
<find>prop36</find>
<find>Electrical</find>
<find>operator</find>
<find>commit</find>
</findStrings>
<replaceStrings>
<replace>operat</replace>
</replaceStrings>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/platform/chip1stop/cate_has_stock.py" />
<option value="$PROJECT_DIR$/platform/chip1stop/cate.py" />
<option value="$PROJECT_DIR$/utils/base.py" />
<option value="$PROJECT_DIR$/update_mysql.py" />
<option value="$PROJECT_DIR$/platform/element14/cate_stock.py" />
<option value="$PROJECT_DIR$/platform/__init__.py" />
<option value="$PROJECT_DIR$/platform/szlc/__init__.py" />
<option value="$PROJECT_DIR$/platform/element14/__init__.py" />
<option value="$PROJECT_DIR$/platform/chip1stop/__init__.py" />
<option value="$PROJECT_DIR$/update_scrip.py" />
<option value="$PROJECT_DIR$/plat/element14/cate_stock.py" />
<option value="$PROJECT_DIR$/updateopera.py" />
<option value="$PROJECT_DIR$/clean.py" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="488" />
<option name="y" value="405" />
<option name="width" value="1400" />
<option name="height" value="1000" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="update_cate" type="b2602c69:ProjectViewProjectNode" />
<item name="update_cate" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="settings.editor.selected.configurable" value="configurable.group.appearance" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="E:\my\update_cate\platform" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="Python.update_scrip">
<configuration name="cate_stock" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="update_cate" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/platform/element14" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/platform/element14/cate_stock.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="clean" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="update_cate" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/clean.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="update_scrip" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="update_cate" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/update_scrip.py" />
<option name="PARAMETERS" value="element14" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="updateopera" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="update_cate" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/updateopera.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<list>
<item itemvalue="Python.cate_stock" />
<item itemvalue="Python.update_scrip" />
<item itemvalue="Python.clean" />
<item itemvalue="Python.updateopera" />
</list>
<recent_temporary>
<list>
<item itemvalue="Python.update_scrip" />
<item itemvalue="Python.updateopera" />
<item itemvalue="Python.clean" />
<item itemvalue="Python.cate_stock" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="bdc1212b-a67e-465a-8c9c-03055b5d227f" name="Default Changelist" comment="" />
<created>1554356907352</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1554356907352</updated>
<workItem from="1554356908814" duration="13601000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="13601000" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<layout>
<window_info id="Favorites" side_tool="true" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Docker" show_stripe_button="false" />
<window_info anchor="bottom" id="Database Changes" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Python Console" />
<window_info anchor="bottom" id="Terminal" weight="0.32924107" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32924107" />
<window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.27455357" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="SciView" />
<window_info anchor="right" id="Database" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
<layout-to-restore>
<window_info id="Favorites" order="0" side_tool="true" />
<window_info active="true" content_ui="combo" id="Project" order="1" visible="true" weight="0.25" />
<window_info id="Structure" order="2" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Docker" order="0" show_stripe_button="false" />
<window_info anchor="bottom" id="Terminal" order="1" />
<window_info anchor="bottom" id="Event Log" order="2" side_tool="true" />
<window_info anchor="bottom" id="Database Changes" order="3" />
<window_info anchor="bottom" id="Version Control" order="4" />
<window_info anchor="bottom" id="Python Console" order="5" />
<window_info anchor="bottom" id="Message" order="6" />
<window_info anchor="bottom" id="Find" order="7" />
<window_info anchor="bottom" id="Run" order="8" visible="true" weight="0.43973213" />
<window_info anchor="bottom" id="Debug" order="9" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="10" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="11" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="12" />
<window_info anchor="right" id="Database" order="0" />
<window_info anchor="right" id="SciView" order="1" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="2" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="3" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="4" weight="0.25" />
</layout-to-restore>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/utils/mysqlops.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/utils/clean_db.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/utils/base.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="210">
<caret line="10" lean-forward="true" selection-start-line="10" selection-end-line="10" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/plat/chip1stop/cate_stock.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-504">
<caret selection-end-line="2" selection-end-column="42" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/plat/__init__.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/plat/chip1stop/__init__.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/plat/element14/__init__.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/plat/szlc/__init__.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://D:/manyvenv/tornado_api_server/Lib/site-packages/pymysql/connections.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="189">
<caret line="480" column="8" selection-start-line="480" selection-start-column="8" selection-end-line="480" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/plat/chip1stop/cate.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="609">
<caret line="84" column="34" lean-forward="true" selection-start-line="84" selection-start-column="34" selection-end-line="84" selection-end-column="54" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/plat/szlc/cate_stock.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="329">
<caret line="104" column="12" lean-forward="true" selection-start-line="104" selection-start-column="12" selection-end-line="104" selection-end-column="32" />
<folding>
<element signature="e#154#718#0" />
<element signature="e#760#2320#0" />
<element signature="e#1304#2298#0" />
<element signature="e#1850#2266#0" />
<element signature="e#2847#2922#0" />
<element signature="e#2882#2922#0" />
<element signature="e#2966#3053#0" />
<element signature="e#2996#3053#0" />
<element signature="e#3986#4126#0" />
<element signature="e#4009#4110#0" />
<element signature="e#4035#4110#0" />
<element signature="e#4070#4110#0" />
<element signature="e#4222#4910#0" />
<element signature="e#4251#4881#0" />
<element signature="e#4291#4881#0" />
<element signature="e#4331#4550#0" />
<element signature="e#4593#4881#0" />
<element signature="e#4599#4755#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/plat/element14/cate_stock.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="58">
<caret line="28" column="82" lean-forward="true" selection-start-line="28" selection-start-column="82" selection-end-line="28" selection-end-column="98" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/clean.py">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret selection-end-line="14" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/utils/mysqlopera.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="42">
<caret line="2" lean-forward="true" selection-start-line="2" selection-end-line="2" />
<folding>
<element signature="e#45#55#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/update_scrip.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="231">
<caret line="11" lean-forward="true" selection-start-line="11" selection-end-line="11" />
<folding>
<element signature="e#0#13#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/updateopera.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="462">
<caret line="22" column="62" lean-forward="true" selection-start-line="22" selection-start-column="62" selection-end-line="22" selection-end-column="62" />
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
No preview for this file type
# from utils.mysqlopera import MySqlOperator
# sqler = MySqlOperator('element14')
# with sqler.db.cursor() as cursor:
# sql = 'select cat_id,cat_name,url from lie_category where cat_name like "http%"'
# cursor.execute(sql)
# a=cursor.fetchall()
# for per in a:
# sql = 'UPDATE lie_category SET url=%s,cat_name=%s where cat_id=%s '
# data=(per[1],per[2],per[0])
# cursor.execute(sql,data)
# sqler.db.commit()
# # c=[]
# # for per in a:
# # c.append(per[0])
File mode changed
No preview for this file type
import re, requests
from lxml import etree
from utils.mysqlopera import MySqlOperator
operator = MySqlOperator('chip1stop')
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Host": "www.chip1stop.com",
"Referer": "https://www.chip1stop.com/HKG/zh",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
}
domain = 'https://www.chip1stop.com'
catelist_url = 'https://www.chip1stop.com/HKG/zh/category'
item_name_pattern = re.compile(r'([^(]*)(')
item_num_pattern = re.compile(r'[^(]*((\d*,*\d*,*\d+))')
var = {
'cat_name': None,
'parent_id': None,
'sort_order': 50,
"is_show": 1,
"url": None,
"islast": None,
"level": None,
"page_count": 0
}
def get_level_1():
resp = requests.get(catelist_url, headers=headers).text
dom = etree.HTML(resp)
# level_1doms = dom.xpath('//ul[@class="m-flex m-flex--c4 m-flex--g40 m-mt categoryUlClick"]//li')
# for li in level_1doms:
# level_1title = li.xpath('.//span[@class="m-text-16 m-font-b m-color-bl m-mt-s"]/text()')[0]
# level_1href = domain + li.xpath('./a/@href')[0]
# print(level_1title,level_1href)
level_doms = dom.xpath('//div[@class="clear box_t10 categoryanchorTop categoryanchorHeight"]//section')
for se in level_doms:
level_1 = {}
level_1['cat_name'] = se.xpath('.//h3/a/text()')[0].strip()
level_1['parent_id'] = 0
level_1['sort_order'] = 50
level_1['is_show'] = 1
level_1['url'] = domain + se.xpath('.//h3/a/@href')[0]
level_1['islast'] = 0
level_1['level'] = 1
level_1['page_count'] = 0
level_1_sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
level_1_data = (
level_1['cat_name'], level_1['parent_id'], level_1['sort_order'], level_1['is_show'], level_1['url'],
level_1['islast'], level_1['level'], level_1['page_count'])
with operator.db.cursor() as cursor:
cursor.execute(level_1_sql,level_1_data)
operator.db.commit()
cursor.execute("select max(cat_id) from lie_category")
level_1_incby_id = cursor.fetchone()[0]
print('一级分类'+str(level_1_incby_id))
level_2doms = se.xpath('.//div[@class="categoryListDl clearfix"]')
for level_2dom in level_2doms:
level_2 = {}
level_2['cat_name'] = level_2dom.xpath('.//h4//a')[0].xpath('string(.)').strip()
level_2['parent_id'] = level_1_incby_id
level_2['sort_order'] = 50
level_2['is_show'] = 1
level_2['url'] =domain + level_2dom.xpath('.//h4//a/@href')[0]
level_2['islast'] = 0
level_2['level'] = 2
level_2['page_count'] = 0
level_2_sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
level_2_data = (
level_2['cat_name'], level_2['parent_id'], level_2['sort_order'], level_2['is_show'], level_2['url'],
level_2['islast'], level_2['level'], level_2['page_count'])
with operator.db.cursor() as cursor:
cursor.execute(level_2_sql, level_2_data)
operator.db.commit()
cursor.execute("select max(cat_id) from lie_category")
level_2_incby_id =cursor.fetchone()[0]
print('二级分类' + str(level_2_incby_id))
level_3doms = level_2dom.xpath('.//ul//li')
for level_3dom in level_3doms:
level_3 = {}
level_3['cat_name'] = item_name_pattern.findall(level_3dom.xpath('.//a/text()')[0].strip())[0]
level_3['parent_id'] = level_2_incby_id
level_3['sort_order'] = 50
level_3['is_show'] = 1
level_3['url'] = domain + level_3dom.xpath('.//a/@href')[0]
level_3['islast'] = 1
level_3['level'] = 3
level_3['page_count'] = 0
level_3_sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
level_3_data = (
level_3['cat_name'], level_3['parent_id'], level_3['sort_order'], level_3['is_show'],
level_3['url'],
level_3['islast'], level_3['level'], level_3['page_count'])
with operator.db.cursor() as cursor:
cursor.execute(level_3_sql, level_3_data)
operator.db.commit()
# level_3num = item_num_pattern.findall(level_3title)[0].replace(',', '')
# print(level_3name,level_3num,level_3href)
if __name__ == '__main__':
get_level_1()
import re, requests
from lxml import etree
from utils.mysqlopera import MySqlOperator
operator = MySqlOperator('chip1stop')
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Host": "www.chip1stop.com",
"Referer": "https://www.chip1stop.com/HKG/zh",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
}
domain = 'https://www.chip1stop.com'
catelist_url = 'https://www.chip1stop.com/HKG/zh/stock'
item_name_pattern = re.compile(r'([^\[]*)')
item_num_pattern = re.compile(r'\[([0-9,]*)\]')
var = {
'cat_name': None,
'parent_id': None,
'sort_order': 50,
"is_show": 1,
"url": None,
"islast": None,
"level": None,
"page_count": 0
}
def get_level_1():
resp = requests.get(catelist_url, headers=headers).text
dom = etree.HTML(resp)
# level_doms = dom.xpath('//div[@class="clear box_t10 categoryanchorTop categoryanchorHeight"]//section')
level_doms = dom.xpath('//div[@class="m-news-tab-content js-tab-target is-active"]//section[not(@id="a-product-01")]')
for se in level_doms:
level_1 = {}
level_1['cat_name'] = se.xpath('.//h3/a/text()')[0].strip()
level_1['parent_id'] = 0
level_1['sort_order'] = 50
level_1['is_show'] = 1
level_1['url'] = domain + se.xpath('.//h3/a/@href')[0]
level_1['islast'] = 0
level_1['level'] = 1
level_1['page_count'] = 0
level_1_sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
level_1_data = (
level_1['cat_name'], level_1['parent_id'], level_1['sort_order'], level_1['is_show'], level_1['url'],
level_1['islast'], level_1['level'], level_1['page_count'])
with operator.db.cursor() as cursor:
cursor.execute(level_1_sql,level_1_data)
operator.db.commit()
cursor.execute("select max(cat_id) from lie_category")
level_1_incby_id = cursor.fetchone()[0]
print('一级分类:'+str(level_1['cat_name']))
level_2doms = se.xpath('.//h4[@class="m-bor-title m-text-16 m-mt"]')
for level_2dom in level_2doms:
level_2 = {}
level_2['cat_name'] = level_2dom.xpath('.//a')[0].xpath('string(.)').strip()
level_2['parent_id'] = level_1_incby_id
level_2['sort_order'] = 50
level_2['is_show'] = 1
level_2['url'] =domain + level_2dom.xpath('.//a/@href')[0]
level_2['islast'] = 0
level_2['level'] = 2
level_2['page_count'] = 0
level_2_sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
level_2_data = (
level_2['cat_name'], level_2['parent_id'], level_2['sort_order'], level_2['is_show'], level_2['url'],
level_2['islast'], level_2['level'], level_2['page_count'])
with operator.db.cursor() as cursor:
cursor.execute(level_2_sql, level_2_data)
operator.db.commit()
cursor.execute("select max(cat_id) from lie_category")
level_2_incby_id =cursor.fetchone()[0]
print('二级分类:' + str(level_2['cat_name']))
level_3doms = level_2dom.xpath('./following-sibling::ul[1]//a')
for level_3dom in level_3doms:
level_3 = {}
level_3['cat_name'] = item_name_pattern.findall(level_3dom.xpath('./text()')[0].strip())[0]
level_3['parent_id'] = level_2_incby_id
level_3['sort_order'] = 50
level_3['is_show'] = 1
level_3['url'] = domain + level_3dom.xpath('./@href')[0]
level_3['islast'] = 1
level_3['level'] = 3
level_3['page_count'] = 0
level_3_sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
level_3_data = (
level_3['cat_name'], level_3['parent_id'], level_3['sort_order'], level_3['is_show'],
level_3['url'],
level_3['islast'], level_3['level'], level_3['page_count'])
with operator.db.cursor() as cursor:
cursor.execute(level_3_sql, level_3_data)
operator.db.commit()
# level_3num = item_num_pattern.findall(level_3title)[0].replace(',', '')
# print(level_3name,level_3num,level_3href)
print('三级分类:' + level_3['cat_name'])
if __name__ == '__main__':
get_level_1()
from utils.base import Module_Base
url = 'https://hk.element14.com/browse-for-products'
# url='http://httpbin.org/ip'
a = Module_Base()
headers = {
"authority": "cn.element14.com",
"method": "GET",
"path": "/browse-for-products",
"scheme": "https",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9",
"cache-control": "max-age=0",
"referer": "https://cn.element14.com/",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
}
resp = a.requests.session().get(url, headers=headers).text
doms = a.etree.HTML(resp)
cate_pagecount_pattern = a.re.compile('')
content_sections = doms.xpath('//div[@class="categoryContainer"]//section')
levels = []
for content_dom in content_sections:
level1 = dict()
level1['cat_name'] = content_dom.xpath('.//div[@class="catHeaderWrapper"]//h2//a/text()')[0].strip()
level1['url'] = content_dom.xpath('.//div[@class="catHeaderWrapper"]//h2//a/@href')[0].strip()
level1['level'] = 1
level1['islast'] = 0
level1['parent_id'] = 0
level1['level2_list'] = []
# print('一级分类',level1['cat_name'])
level2_doms = content_dom.xpath('.//nav//ul')
for level2_dom in level2_doms:
level2 = {}
level2['cat_name'] = level2_dom.xpath('.//li//a/text()')[0]
level2['url'] = level2_dom.xpath('.//li//a/@href')[0]
level2['level'] = 2
level2['islast'] = 1
level1['level2_list'].append(level2)
# print('二级分类',level2['cat_name'])
levels.append(level1)
File mode changed
#!encoding:utf-8
import requests
from lxml import etree
import re
from utils.mysqlopera import MySqlOperator
operator = MySqlOperator('szlc')
headers = {
"authority": "www.szlcsc.com",
"method": "GET",
"path": "/catalog.html",
"scheme": "https",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9",
"cache-control": "max-age=0",
"if-modified-since": "Wed, 13 Mar 2019 02:15:00 GMT",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"}
# 拿到所有一级二级分类数据
def get_szlc_all():
# level_name_pattern = re.compile(r'\d+\.(.*)\(.*\)')
level_name_pattern = re.compile(r'([^\(]*) \(')
level_num_pattern = re.compile(r'[^\(]*\((\d+)\)')
level2_name_pattern = re.compile(r'([^\(]*)\(')
url = 'https://www.szlcsc.com/catalog.html'
resp = requests.get(url, headers=headers)
resp.encoding = 'utf-8'
dom_html = etree.HTML(resp.text)
# cates=dom_html.xpath('//div[@class="catalog_a"]//dt/a/text()')
doms_cate = dom_html.xpath('//div[@class="item"]')
all = []
for dom in doms_cate:
per_1_cate = {}
print(dom.xpath('./a/text()')[2])
per_1_cate['name'] = level_name_pattern.findall(dom.xpath('./a/text()')[2])[0].strip()
per_1_cate['num'] = int(level_num_pattern.findall(dom.xpath('./a/text()')[2])[0])
per_1_cate['url'] = dom.xpath('./a/@href')[0]
per_1_cate['level'] = 1
per_1_cate['islast'] = 0
per_1_cate['parent_id'] = 0
doms_2cate = dom.xpath('.//div[@class="child-item"]')
per_1_cate['2_list'] = []
for dom_cate_2 in doms_2cate:
per_2_cate = {}
per_2_cate['name'] = level2_name_pattern.findall(dom_cate_2.xpath('.//a/text()')[0])[0].strip()
per_2_cate['num'] = int(level_num_pattern.findall(dom_cate_2.xpath('.//a/text()')[0])[0])
per_2_cate['url'] = dom_cate_2.xpath('.//a/@href')[0]
per_1_cate['level'] = 2
per_1_cate['islast'] = 1
per_1_cate['2_list'].append(per_2_cate)
all.append(per_1_cate)
#
return all
# 数据库所有分类的is_show设置为0
def clean_db():
with operator.db.cursor() as cursor:
sql = "update lie_category set is_show = 0"
cursor.execute(sql)
operator.db.commit()
# 拿到所有旧的分类的名字和ID
def get_old_allname_and_cat_id():
with operator.db.cursor() as cursor:
sql = "select cat_id,cat_name from lie_category "
cursor.execute(sql)
old = cursor.fetchall()
return old
# 给一级分类数据找到或者生成新ID,给二级分类找到ID
def add_cat_id(all, old):
for i in all:
for d in old:
if i['name'] in d:
i['cat_id'] = d[0]
break
for c in i['2_list']:
for g in old:
if c['name'] in g:
c['cat_id'] = g[0]
with operator.db.cursor() as cursor:
for i in all:
if i.get('cat_id'):
sql = 'UPDATE lie_category SET parent_id=%s,is_show=%s, url=%s,islast=%s,level=%s WHERE cat_id=%s'
data = (0, 1, i['url'], 0, 1, i['cat_id'])
cursor.execute(sql, data)
else:
sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
data = (i["name"], 0, 50, 1, i["url"], 0, 1, 0)
cursor.execute(sql, data)
operator.db.commit()
return all
# 拿到新的一级分类的ID
def get_new_allname_and_cat_id():
with operator.db.cursor() as cursor:
sql = "select cat_id,cat_name from lie_category "
cursor.execute(sql)
new = cursor.fetchall()
return new
# 给一级分类添加ID
def add_more_cat_id(all_, new):
for i in all_:
for d in new:
if i['name'] in d:
i['cat_id'] = d[0]
break
return all_
# 给二级分类添加parent_id,生成自己的新ID
def over(all_):
with operator.db.cursor() as cursor:
for a_1 in all_:
for s in a_1['2_list']:
if s.get('cat_id'):
sql = 'UPDATE lie_category SET parent_id=%s,is_show=%s, url=%s,islast=%s,level=%s WHERE cat_id=%s'
data = (a_1['cat_id'], 1, s['url'], 1, 2, s['cat_id'])
cursor.execute(sql, data)
else:
sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
data = (s["name"], a_1['cat_id'], 50, 1, s["url"], 1, 2, 0)
cursor.execute(sql, data)
operator.db.commit()
if __name__ == '__main__':
clean_db()
old = get_old_allname_and_cat_id()
all = get_szlc_all()
all_ = add_cat_id(all, old)
new = get_new_allname_and_cat_id()
all_ = add_more_cat_id(all_, new)
over(all_)
import sys
from updateopera import Updater
import importlib
if __name__ == '__main__':
plat_name = sys.argv[1]
module_name = 'plat.{}.cate_stock'.format(plat_name)
module = importlib.import_module(module_name)
updater = Updater(plat_name)
updater.up(module.levels)
from utils.mysqlopera import MySqlOperator
class Updater():
def __init__(self, db_name):
self.operator = MySqlOperator(db_name)
def clean_db(self):
with self.operator.db.cursor() as cursor:
sql = "update lie_category set is_show = 0"
cursor.execute(sql)
def get_cat_id(self, cat_name):
with self.operator.db.cursor() as cursor:
sql = 'select cat_id from lie_category where cat_name =%s'
cursor.execute(sql, cat_name)
result = cursor.fetchone()
result = result[0] if result else None
return result
def update(self, cat_id, url, islast, level, parent_id=0,is_show=1):
with self.operator.db.cursor() as cursor:
sql = 'UPDATE lie_category SET url=%s,islast=%s,level=%s,is_show=%s, parent_id=%s where cat_id=%s'
data=(url,islast, level, is_show,cat_id,parent_id)
cursor.execute(sql, data)
def insert(self, cat_name, url, islast, level, parent_id=0, is_show=1, sort_order=50, page_count=1):
with self.operator.db.cursor() as cursor:
sql = 'INSERT into lie_category(cat_name,parent_id,sort_order,is_show,url,islast,level,page_count) values' \
'(%s,%s,%s,%s,%s,%s,%s,%s)'
data = (cat_name, parent_id, sort_order, is_show, url, islast, level, page_count)
cursor.execute(sql, data)
cursor.execute("select max(cat_id) from lie_category")
cat_id=cursor.fetchone()[0]
return cat_id
def up(self,levels):
self.clean_db()
for level1 in levels:
cat1_id=self.get_cat_id(level1['cat_name'])
if cat1_id:
self.update(cat1_id,level1['url'],level1['islast'],level1['level'])
else:
cat1_id = self.insert(level1['cat_name'], level1['url'], level1['islast'], level1['level'], level1['parent_id'])
print('一级分类',level1['cat_name'])
for level2 in level1.get('level2_list'):
if level2['islast']:
cat2_id=self.get_cat_id(level2['cat_name'])
if cat2_id:
self.update(cat2_id,level2['url'],level2['islast'],level2['level'],cat1_id)
else:
self.insert(level2['cat_name'],level2['url'],level2['islast'],level2['level'],cat1_id)
print('二级分类',level2['cat_name'])
else:
pass #TODO 增加三级分类
self.operator.db.commit()
\ No newline at end of file
No preview for this file type
No preview for this file type
import re, requests,json
from lxml import etree
from utils.mysqlopera import MySqlOperator
class Module_Base():
re=re
requests=requests
json=json
etree=etree
mysql_opera=MySqlOperator
#!encoding:utf-8
old=((1, '滤波器'), (2, '共模扼流圈'), (3, '磁珠'), (4, '陶瓷滤波器'), (5, 'RF滤波器'), (6, 'SAW滤波器'), (7, '馈通式电容器'), (8, '功能模块'), (9, '模块'), (10, '套件'), (11, '无线模块'), (12, 'GSM/GPRS/GPS模块'), (13, 'WIFI模块'), (14, '方案验证板'), (15, '方案验证板'), (16, '免费赠品区'), (17, '各类开发板'), (18, '其余赠品'), (19, '处理器及微控制器'), (20, 'ABOV'), (21, 'EastSoft'), (22, 'ELAN'), (23, 'Fortior Technol'), (24, 'Infineon'), (25, 'MDT'), (26, 'PADAUK'), (27, 'SONIX'), (28, 'WCH'), (29, '华芯微特'), (30, '钜泉光电'), (31, '处理器及微控制器'), (32, 'HOLTEK'), (33, 'GigaDevice'), (34, 'Allwinner'), (35, 'ATMEL/AVR'), (36, 'ST'), (37, 'ADI'), (38, 'MICROCHIP'), (39, 'NXP'), (40, 'TI'), (41, 'STC'), (42, 'FREESCALE'), (43, 'NUVOTON'), (44, 'CYPRESS'), (45, 'SST'), (46, 'SYNCMOS'), (47, 'MEGAWIN'), (48, 'RENESAS'), (49, 'SILICON LABS'), (50, 'SAMSUNG'), (51, 'HISILTC'), (52, '嵌入式外围芯片'), (53, '字库芯片'), (54, '端口扩展芯片'), (55, 'MCU监控芯片'), (56, '驱动芯片'), (57, '实时时钟芯片'), (58, '嵌入式外围芯片'), (59, '逻辑芯片'), (60, '编解码芯片'), (61, '74系列逻辑芯片'), (62, '4000系列逻辑芯片'), (63, '时基集成芯片'), (64, 'CPLD/FPGA芯片'), (65, '逻辑芯片'), (66, '存储器'), (67, 'DDR存储器'), (68, 'EPROM存储器'), (69, 'PROM存储器'), (70, 'FLASH存储器'), (71, 'EEPROM存储器'), (72, 'RAM存储器'), (73, 'FRAM存储器'), (74, 'FIFO存储器'), (75, '电源芯片'), (76, '电池保护芯片'), (77, '电源监控芯片'), (78, '电源模块AC-DC'), (79, '功率开关芯片'), (80, '电源模块DC-DC'), (81, '线性稳压芯片'), (82, '低压差线性稳压'), (83, 'DC-DC芯片'), (84, '电压基准芯片'), (85, '开关电源芯片'), (86, '电源芯片'), (87, '电池电源管理芯片'), (88, '模拟芯片'), (89, '电流监控芯片'), (90, '电量计芯片'), (91, '模拟开关芯片'), (92, '模数转换芯片'), (93, '数模转换芯片'), (94, '模拟芯片'), (95, '数字电位器芯片'), (96, '接口芯片'), (97, 'USB芯片'), (98, 'RS232芯片'), (99, 'RS-485/RS-422芯片'), (100, '以太网芯片'), (101, '隔离器芯片'), (102, 'CAN芯片'), (103, 'LVDS芯片'), (104, '4-20MA接口芯片'), (105, '音频接口芯片'), (106, '接口芯片'), (107, 'DDS芯片'), (108, '放大器、线性器件'), (109, '通用运放'), (110, '放大器'), (111, '高速、宽带运放'), (112, '仪表运放'), (113, '精密运放'), (114, 'FET输入运放'), (115, '低噪声运放'), (116, '低功耗运放'), (117, '电压比较器'), (118, '音频放大器'), (119, '差分运放'), (120, '驱动器'), (121, 'IGBT驱动'), (122, 'EL驱动'), (123, 'LED驱动'), (124, 'LCD驱动'), (125, 'MOS驱动'), (126, '电机驱动'), (127, '可控硅驱动'), (128, '大电流驱动'), (129, '驱动芯片'), (130, '传感器'), (131, '传感器'), (132, '温度传感器'), (133, '颜色传感器'), (134, '图像传感器'), (135, '加速度传感器'), (136, '触摸芯片'), (137, '温湿度传感器'), (138, '环境光传感器'), (139, '红外传感器'), (140, '二极管'), (141, 'ESD二极管'), (142, '雪崩二极管'), (143, '高效率二极管'), (144, '恒流二极管'), (145, '变容二极管'), (146, '通用二极管'), (147, '稳压二极管'), (148, '肖特基二极管'), (149, '快恢复二极管'), (150, '超快恢复二极管'), (151, '开关二极管'), (152, '触发二极管'), (153, 'TVS二极管'), (154, '高压二极管'), (155, '整流桥'), (156, '放电管'), (157, '射频/无线电'), (158, 'RF 放大器'), (159, 'RF 混频器'), (160, 'RF 检测器'), (161, 'RF 天线'), (162, 'RF 配件'), (163, 'RF 衰减器'), (164, '射频开关'), (165, '射频卡芯片'), (166, '无线收发芯片'), (167, '电阻'), (168, 'MELF 电阻'), (169, '贴片电阻'), (170, '金属膜电阻'), (171, '贴片排阻'), (172, '碳膜电阻'), (173, '直插排阻'), (174, '可调电阻'), (175, '精密可调电阻'), (176, '光敏电阻'), (177, '水泥电阻'), (178, 'NTC 热敏电阻'), (179, 'PTC 热敏电阻'), (180, '压敏电阻'), (181, '保险电阻'), (182, '绕线电阻'), (183, '氧化膜电阻'), (184, '电位器、其他可调电阻'), (185, '金属氧化膜电阻'), (186, '贴片超低阻值电阻'), (187, '贴片合金电阻'), (188, '贴片高精密、低温漂电阻'), (189, 'LED灯条电阻'), (190, '金属玻璃釉电阻'), (191, '采样电阻'), (192, '电容'), (193, '固态电解电容'), (194, '氧化铌电容'), (195, 'CL21电容'), (196, '聚酯薄膜电容'), (197, '超级电容器'), (198, '贴片电容'), (199, '钽电容'), (200, '贴片电解电容'), (201, '直插电解电容'), (202, '直插瓷片电容'), (203, '直插独石电容'), (204, '安规电容'), (205, '高压电容'), (206, '可调电容'), (207, '涤纶电容'), (208, 'CBB电容'), (209, '校正电容'), (210, '光耦/发光管/红外'), (211, '红外发射管'), (212, 'LED点阵'), (213, 'LCD液晶显示模块'), (214, '光电固态继电器'), (215, '光电可控硅'), (216, 'OLED显示模块'), (217, 'VFD显示模块'), (218, '菲涅尔透镜'), (219, 'IrDA红外收发器'), (220, '发光二极管'), (221, '红外接收管'), (222, '光电开关'), (223, '直插光耦'), (224, '贴片光耦'), (225, '硅光电池'), (226, 'LED数码管'), (227, '晶振'), (228, '49SMD晶振'), (229, '49S晶振'), (230, '49U晶振'), (231, '圆柱体晶振'), (232, '贴片有源晶振'), (233, '声表面谐振器'), (234, '陶瓷谐振器'), (235, '直插有源晶振'), (236, '贴片无源晶振'), (237, '晶体管'), (238, 'IGBT管'), (239, '晶体管'), (240, '数字三极管'), (241, '达林顿管'), (242, 'MOS'), (243, '可控硅'), (244, '三极管'), (245, '电感/磁珠/变压器'), (246, '色环电感'), (247, '工字电感'), (248, '电源变压器'), (249, '共模电感'), (250, '滤波器'), (251, '直插磁珠'), (252, '天线'), (253, '高频电感'), (254, '互感器'), (255, '低频电感'), (256, '贴片电感'), (257, '贴片磁珠'), (258, '网口变压器'), (259, '功率电感'), (260, '保险丝'), (261, '短路器'), (262, '断路器'), (263, '一次性保险丝'), (264, '直插保险丝'), (265, '贴片保险丝'), (266, '玻璃管保险丝'), (267, '保险丝夹/座'), (268, '按键开关/继电器'), (269, '拨动开关'), (270, '旋转编码开关'), (271, '带灯开关'), (272, '锅仔片'), (273, '继电器'), (274, '按键开关'), (275, '船型开关'), (276, '行程开关'), (277, '轻触开关'), (278, '拨码开关'), (279, '五向开关'), (280, '多功能开关'), (281, '蜂鸣器/扬声器/咪头'), (282, '咪头/硅麦'), (283, '扬声器'), (284, '蜂鸣器'), (285, '电源电池'), (286, '电池'), (287, '电池盒/电池座'), (288, '电源适配器'), (289, '五金类/其他'), (290, '硅胶'), (291, '螺丝'), (292, '螺柱'), (293, '散热器'), (294, '测试针'), (295, '导热胶'), (296, '电子辅料'), (297, '电路板DIY专区/书籍'), (298, '1.6双面覆铜FR-4玻纤板'), (299, 'PCB磨板砂纸'), (300, 'PCB设计书籍'), (301, '连接器'), (302, '音频连接器'), (303, '牛角连接器'), (304, 'CH连接器'), (305, 'VH连接器'), (306, 'PH连接器'), (307, 'XH连接器'), (308, '2EDG连接器'), (309, '15EDG连接器'), (310, '1.25T连接器'), (311, 'D-SUB连接器'), (312, '卡座'), (313, 'RJ11连接器'), (314, '排针'), (315, '排母'), (316, '短路帽'), (317, 'BNC连接器'), (318, 'PS2连接器'), (319, 'KF2510连接器'), (320, 'AV连接器'), (321, 'micro usb连接器'), (322, 'USB Type-C连接器'), (323, '杜邦'), (324, 'EH连接器'), (325, '光纤连接器'), (326, 'ZH连接器1.5mm'), (327, 'DVI连接器'), (328, '压线端子'), (329, 'RJ22连接器'), (330, 'HDMI连接器'), (331, '板对板连接器'), (332, 'IDC连接器'), (333, '香蕉头连接器'), (334, '夹子'), (335, '隔灯柱'), (336, 'IC座'), (337, '连接器'), (338, 'USB连接器'), (339, 'RJ45连接器'), (340, '接线端子'), (341, 'FPC连接器'), (342, 'DC连接器'), (343, '线材/焊接材料'), (344, 'FFC连接线'), (345, '信号线/数据线'), (346, '电源线'), (347, '焊锡丝'), (348, '电线'), (349, '助焊膏'), (350, '焊锡膏'), (351, '焊锡球'), (352, '助焊剂'), (353, '绿油'), (354, '红胶'), (355, '电子线及相关'), (356, '工具/辅材'), (357, '液态光学胶'), (358, '焊接工具'), (359, '测电笔'), (360, '胶水'), (361, 'UPS电源'), (362, '扣件'), (363, '导电银浆'), (364, '仪器'), (365, '黄胶'), (366, '化工辅材'), (367, '热缩管'), (368, '其他'), (369, '吸锡带'), (370, '刀具'), (371, '双面胶'), (372, '镊子'), (373, '治具'), (374, 'PVC膜'), (375, '酒精瓶'), (376, '螺丝刀/钳'), (377, '通用辅材'), (378, '万用表/仪表'), (379, '万用表表笔'), (380, '万用组合式零件盒'), (381, '马达'), (382, '微电机/马达'), (383, '万能板'), (384, '万能板'), (385, '面包板'), (1170, '未分类'), (1171, '未分类'), (1172, '高压电阻'), (1173, '温控开关'), (1180, '开发套件与仿真器'), (1179, '通讯模块'), (1181, 'SDRAM存储器'), (1182, '平衡-不平衡变压器'), (1183, 'RF 定向耦合器'), (1184, '贴片电阻'), (1185, '气体传感器'), (1186, '压力传感器'), (1187, '特殊功能放大器'), (1188, '触摸屏控制器'), (1189, 'PTC自恢复保险丝'), (1190, '测试点/测试环'), (1191, '焊接/快插端子'), (1192, 'AC电源插座'), (1193, '电池附件/弹片/弹簧'), (1194, '包装袋'), (1195, '隔离柱及垫片'), (1196, '工程部二次分类--资料'), (1197, '工程部二次分类--型号'), (1177, '低压差线性稳压(LDO)'), (1176, '连接器附件'), (1178, '传感器模块'), (1175, '交流接触器'), (1174, '开关插座'))
from utils.mysqlopera import MySqlOperator
operator=MySqlOperator('szlc')
with operator.db.cursor() as cursor:
sql="select cat_id,cat_name from lie_category "
cursor.execute(sql)
old_old=cursor.fetchall()
# old_old=((1, '滤波器'), (2, '共模扼流圈'), (3, '磁珠'), (4, '陶瓷滤波器'), (5, 'RF滤波器'), (6, 'SAW滤波器'), (7, '馈通式电容器'), (8, '功能模块'), (9, '模块'), (10, '套件'), (11, '无线模块'), (12, 'GSM/GPRS/GPS模块'), (13, 'WIFI模块'), (14, '方案验证板'), (15, '方案验证板'), (16, '免费赠品区'), (17, '各类开发板'), (18, '其余赠品'), (19, '处理器及微控制器'), (20, 'ABOV'), (21, 'EastSoft'), (22, 'ELAN'), (23, 'Fortior Technol'), (24, 'Infineon'), (25, 'MDT'), (26, 'PADAUK'), (27, 'SONIX'), (28, 'WCH'), (29, '华芯微特'), (30, '钜泉光电'), (31, '处理器及微控制器'), (32, 'HOLTEK'), (33, 'GigaDevice'), (34, 'Allwinner'), (35, 'ATMEL/AVR'), (36, 'ST'), (37, 'ADI'), (38, 'MICROCHIP'), (39, 'NXP'), (40, 'TI'), (41, 'STC'), (42, 'FREESCALE'), (43, 'NUVOTON'), (44, 'CYPRESS'), (45, 'SST'), (46, 'SYNCMOS'), (47, 'MEGAWIN'), (48, 'RENESAS'), (49, 'SILICON LABS'), (50, 'SAMSUNG'), (51, 'HISILTC'), (52, '嵌入式外围芯片'), (53, '字库芯片'), (54, '端口扩展芯片'), (55, 'MCU监控芯片'), (56, '驱动芯片'), (57, '实时时钟芯片'), (58, '嵌入式外围芯片'), (59, '逻辑芯片'), (60, '编解码芯片'), (61, '74系列逻辑芯片'), (62, '4000系列逻辑芯片'), (63, '时基集成芯片'), (64, 'CPLD/FPGA芯片'), (65, '逻辑芯片'), (66, '存储器'), (67, 'DDR存储器'), (68, 'EPROM存储器'), (69, 'PROM存储器'), (70, 'FLASH存储器'), (71, 'EEPROM存储器'), (72, 'RAM存储器'), (73, 'FRAM存储器'), (74, 'FIFO存储器'), (75, '电源芯片'), (76, '电池保护芯片'), (77, '电源监控芯片'), (78, '电源模块AC-DC'), (79, '功率开关芯片'), (80, '电源模块DC-DC'), (81, '线性稳压芯片'), (82, '低压差线性稳压'), (83, 'DC-DC芯片'), (84, '电压基准芯片'), (85, '开关电源芯片'), (86, '电源芯片'), (87, '电池电源管理芯片'), (88, '模拟芯片'), (89, '电流监控芯片'), (90, '电量计芯片'), (91, '模拟开关芯片'), (92, '模数转换芯片'), (93, '数模转换芯片'), (94, '模拟芯片'), (95, '数字电位器芯片'), (96, '接口芯片'), (97, 'USB芯片'), (98, 'RS232芯片'), (99, 'RS-485/RS-422芯片'), (100, '以太网芯片'), (101, '隔离器芯片'), (102, 'CAN芯片'), (103, 'LVDS芯片'), (104, '4-20MA接口芯片'), (105, '音频接口芯片'), (106, '接口芯片'), (107, 'DDS芯片'), (108, '放大器、线性器件'), (109, '通用运放'), (110, '放大器'), (111, '高速、宽带运放'), (112, '仪表运放'), (113, '精密运放'), (114, 'FET输入运放'), (115, '低噪声运放'), (116, '低功耗运放'), (117, '电压比较器'), (118, '音频放大器'), (119, '差分运放'), (120, '驱动器'), (121, 'IGBT驱动'), (122, 'EL驱动'), (123, 'LED驱动'), (124, 'LCD驱动'), (125, 'MOS驱动'), (126, '电机驱动'), (127, '可控硅驱动'), (128, '大电流驱动'), (129, '驱动芯片'), (130, '传感器'), (131, '传感器'), (132, '温度传感器'), (133, '颜色传感器'), (134, '图像传感器'), (135, '加速度传感器'), (136, '触摸芯片'), (137, '温湿度传感器'), (138, '环境光传感器'), (139, '红外传感器'), (140, '二极管'), (141, 'ESD二极管'), (142, '雪崩二极管'), (143, '高效率二极管'), (144, '恒流二极管'), (145, '变容二极管'), (146, '通用二极管'), (147, '稳压二极管'), (148, '肖特基二极管'), (149, '快恢复二极管'), (150, '超快恢复二极管'), (151, '开关二极管'), (152, '触发二极管'), (153, 'TVS二极管'), (154, '高压二极管'), (155, '整流桥'), (156, '放电管'), (157, '射频/无线电'), (158, 'RF 放大器'), (159, 'RF 混频器'), (160, 'RF 检测器'), (161, 'RF 天线'), (162, 'RF 配件'), (163, 'RF 衰减器'), (164, '射频开关'), (165, '射频卡芯片'), (166, '无线收发芯片'), (167, '电阻'), (168, 'MELF 电阻'), (169, '贴片电阻'), (170, '金属膜电阻'), (171, '贴片排阻'), (172, '碳膜电阻'), (173, '直插排阻'), (174, '可调电阻'), (175, '精密可调电阻'), (176, '光敏电阻'), (177, '水泥电阻'), (178, 'NTC 热敏电阻'), (179, 'PTC 热敏电阻'), (180, '压敏电阻'), (181, '保险电阻'), (182, '绕线电阻'), (183, '氧化膜电阻'), (184, '电位器、其他可调电阻'), (185, '金属氧化膜电阻'), (186, '贴片超低阻值电阻'), (187, '贴片合金电阻'), (188, '贴片高精密、低温漂电阻'), (189, 'LED灯条电阻'), (190, '金属玻璃釉电阻'), (191, '采样电阻'), (192, '电容'), (193, '固态电解电容'), (194, '氧化铌电容'), (195, 'CL21电容'), (196, '聚酯薄膜电容'), (197, '超级电容器'), (198, '贴片电容'), (199, '钽电容'), (200, '贴片电解电容'), (201, '直插电解电容'), (202, '直插瓷片电容'), (203, '直插独石电容'), (204, '安规电容'), (205, '高压电容'), (206, '可调电容'), (207, '涤纶电容'), (208, 'CBB电容'), (209, '校正电容'), (210, '光耦/发光管/红外'), (211, '红外发射管'), (212, 'LED点阵'), (213, 'LCD液晶显示模块'), (214, '光电固态继电器'), (215, '光电可控硅'), (216, 'OLED显示模块'), (217, 'VFD显示模块'), (218, '菲涅尔透镜'), (219, 'IrDA红外收发器'), (220, '发光二极管'), (221, '红外接收管'), (222, '光电开关'), (223, '直插光耦'), (224, '贴片光耦'), (225, '硅光电池'), (226, 'LED数码管'), (227, '晶振'), (228, '49SMD晶振'), (229, '49S晶振'), (230, '49U晶振'), (231, '圆柱体晶振'), (232, '贴片有源晶振'), (233, '声表面谐振器'), (234, '陶瓷谐振器'), (235, '直插有源晶振'), (236, '贴片无源晶振'), (237, '晶体管'), (238, 'IGBT管'), (239, '晶体管'), (240, '数字三极管'), (241, '达林顿管'), (242, 'MOS'), (243, '可控硅'), (244, '三极管'), (245, '电感/磁珠/变压器'), (246, '色环电感'), (247, '工字电感'), (248, '电源变压器'), (249, '共模电感'), (250, '滤波器'), (251, '直插磁珠'), (252, '天线'), (253, '高频电感'), (254, '互感器'), (255, '低频电感'), (256, '贴片电感'), (257, '贴片磁珠'), (258, '网口变压器'), (259, '功率电感'), (260, '保险丝'), (261, '短路器'), (262, '断路器'), (263, '一次性保险丝'), (264, '直插保险丝'), (265, '贴片保险丝'), (266, '玻璃管保险丝'), (267, '保险丝夹/座'), (268, '按键开关/继电器'), (269, '拨动开关'), (270, '旋转编码开关'), (271, '带灯开关'), (272, '锅仔片'), (273, '继电器'), (274, '按键开关'), (275, '船型开关'), (276, '行程开关'), (277, '轻触开关'), (278, '拨码开关'), (279, '五向开关'), (280, '多功能开关'), (281, '蜂鸣器/扬声器/咪头'), (282, '咪头/硅麦'), (283, '扬声器'), (284, '蜂鸣器'), (285, '电源电池'), (286, '电池'), (287, '电池盒/电池座'), (288, '电源适配器'), (289, '五金类/其他'), (290, '硅胶'), (291, '螺丝'), (292, '螺柱'), (293, '散热器'), (294, '测试针'), (295, '导热胶'), (296, '电子辅料'), (297, '电路板DIY专区/书籍'), (298, '1.6双面覆铜FR-4玻纤板'), (299, 'PCB磨板砂纸'), (300, 'PCB设计书籍'), (301, '连接器'), (302, '音频连接器'), (303, '牛角连接器'), (304, 'CH连接器'), (305, 'VH连接器'), (306, 'PH连接器'), (307, 'XH连接器'), (308, '2EDG连接器'), (309, '15EDG连接器'), (310, '1.25T连接器'), (311, 'D-SUB连接器'), (312, '卡座'), (313, 'RJ11连接器'), (314, '排针'), (315, '排母'), (316, '短路帽'), (317, 'BNC连接器'), (318, 'PS2连接器'), (319, 'KF2510连接器'), (320, 'AV连接器'), (321, 'micro usb连接器'), (322, 'USB Type-C连接器'), (323, '杜邦'), (324, 'EH连接器'), (325, '光纤连接器'), (326, 'ZH连接器1.5mm'), (327, 'DVI连接器'), (328, '压线端子'), (329, 'RJ22连接器'), (330, 'HDMI连接器'), (331, '板对板连接器'), (332, 'IDC连接器'), (333, '香蕉头连接器'), (334, '夹子'), (335, '隔灯柱'), (336, 'IC座'), (337, '连接器'), (338, 'USB连接器'), (339, 'RJ45连接器'), (340, '接线端子'), (341, 'FPC连接器'), (342, 'DC连接器'), (343, '线材/焊接材料'), (344, 'FFC连接线'), (345, '信号线/数据线'), (346, '电源线'), (347, '焊锡丝'), (348, '电线'), (349, '助焊膏'), (350, '焊锡膏'), (351, '焊锡球'), (352, '助焊剂'), (353, '绿油'), (354, '红胶'), (355, '电子线及相关'), (356, '工具/辅材'), (357, '液态光学胶'), (358, '焊接工具'), (359, '测电笔'), (360, '胶水'), (361, 'UPS电源'), (362, '扣件'), (363, '导电银浆'), (364, '仪器'), (365, '黄胶'), (366, '化工辅材'), (367, '热缩管'), (368, '其他'), (369, '吸锡带'), (370, '刀具'), (371, '双面胶'), (372, '镊子'), (373, '治具'), (374, 'PVC膜'), (375, '酒精瓶'), (376, '螺丝刀/钳'), (377, '通用辅材'), (378, '万用表/仪表'), (379, '万用表表笔'), (380, '万用组合式零件盒'), (381, '马达'), (382, '微电机/马达'), (383, '万能板'), (384, '万能板'), (385, '面包板'), (1170, '未分类'), (1171, '未分类'), (1172, '高压电阻'), (1173, '温控开关'), (1180, '开发套件与仿真器'), (1179, '通讯模块'), (1181, 'SDRAM存储器'), (1182, '平衡-不平衡变压器'), (1183, 'RF 定向耦合器'), (1184, '贴片电阻'), (1185, '气体传感器'), (1186, '压力传感器'), (1187, '特殊功能放大器'), (1188, '触摸屏控制器'), (1189, 'PTC自恢复保险丝'), (1190, '测试点/测试环'), (1191, '焊接/快插端子'), (1192, 'AC电源插座'), (1193, '电池附件/弹片/弹簧'), (1194, '包装袋'), (1198, '射频'), (1195, '隔离柱及垫片'), (1196, '工程部二次分类--资料'), (1197, '工程部二次分类--型号'), (1199, '电感'), (1200, '光耦'), (1201, '线材'), (1202, '五金类'), (1203, '工具'), (1177, '低压差线性稳压(LDO)'), (1176, '连接器附件'), (1178, '传感器模块'), (1175, '交流接触器'), (1174, '开关插座'))
with operator.db.cursor() as cursor:
for i in old_old:
if i not in old:
sql = f"delete from lie_category where cat_id={i[0]}"
cursor.execute(sql)
operator.db.commit()
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import time
import pymysql
def get_env():
if sys.platform in ('darwin', 'win32'):
return 'test'
else:
return 'produce'
ENV = get_env()
HOST_SET = {
'test': '192.168.1.232',
'produce': '172.18.137.37'
}
UP_SET = {
'test': ('ichunt', 'ichunt'),
'produce': ('bigdata', 'bdYm2yy2mmyzlmlly')
}
def get_mysql_conf(db):
host = HOST_SET[ENV]
up = UP_SET[ENV]
conf = {
'host': host,
'port': 3306,
'user': up[0],
'password': up[1],
'db': db,
'charset': 'utf8'
}
return conf
class MySqlOperator(object):
def __init__(self, db_key_name):
config = get_mysql_conf(db_key_name)
self.db = pymysql.connect(**config)
def re_connect(self):
try:
self.db.ping()
except Exception:
self.db.connect()
@staticmethod
def get_ts():
return int(time.time())
def get_hot_kw(self, kid, condition):
with self.db.cursor() as cursor:
sql = "SELECT id, keyword FROM lie_keywords_hot WHERE search_count {} AND id > %s ORDER BY id LIMIT 1000". \
format(condition)
cursor.execute(sql, kid)
result = cursor.fetchall()
return result
def check_kw_exist(self, kw):
with self.db.cursor() as cursor:
sql = 'SELECT 1 FROM lie_keywords_hot WHERE keyword=%s LIMIT 1'
cursor.execute(sql, kw)
result = cursor.fetchone()
return result
def update_kw_count(self, kw):
with self.db.cursor() as cursor:
sql = "UPDATE lie_keywords_hot SET search_count=search_count + 1 WHERE keyword=%s"
cursor.execute(sql, kw)
self.db.commit()
def insert_kw(self, kw):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_keywords_hot(keyword, search_count) VALUES (%s, 1)
"""
cursor.execute(sql, kw)
self.db.commit()
def get_no_bin(self, gid):
with self.db.cursor() as cursor:
sql = """SELECT DISTINCT(productId), id FROM lie_szlc_order_goods WHERE id >%s AND brand_id=0 ORDER BY id
LIMIT 100"""
cursor.execute(sql, gid)
result = cursor.fetchall()
return result
def get_no_pm(self):
with self.db.cursor() as cursor:
sql = "SELECT productId FROM lie_szlc_order_goods WHERE productModel = '' GROUP BY productId"
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_gn_by_gid(self, gid):
with self.db.cursor() as cursor:
sql = "SELECT goods_name FROM szlc.lie_goods WHERE product_id=%s"
cursor.execute(sql, gid)
result = cursor.fetchone()
return result
def update_pm(self, pm, pid):
with self.db.cursor() as cursor:
sql = "UPDATE lie_szlc_order_goods SET productModel=%s WHERE productId=%s"
cursor.execute(sql, (pm, pid))
self.db.commit()
def get_no_bin_count(self):
with self.db.cursor() as cursor:
sql = """SELECT count(DISTINCT(productId)) FROM lie_szlc_order_goods WHERE brand_id=0"""
cursor.execute(sql)
result = cursor.fetchall()
return result
def update_bin(self, data):
with self.db.cursor() as cursor:
sql = "UPDATE lie_szlc_order_goods SET brand_id=%s, brand_name=%s WHERE productId=%s"
cursor.execute(sql, data)
self.db.commit()
# szlc
def get_order_goods_id(self, iid):
with self.db.cursor() as cursor:
sql = "SELECT DISTINCT(productId), id FROM lie_szlc_order_goods WHERE id >%s ORDER BY id LIMIT 100"
cursor.execute(sql, iid)
result = cursor.fetchall()
return result
def get_bid_by_pid(self, pid):
with self.db.cursor() as cursor:
# cursor = self.db.cursor()
sql = "SELECT brand_id FROM szlc.lie_goods WHERE product_id = %s"
cursor.execute(sql, pid)
result = cursor.fetchone()
return result
def get_bn_by_bid(self, bid):
with self.db.cursor() as cursor:
# cursor = self.db.cursor()
sql = "SELECT brand_name FROM szlc.lie_brand WHERE brand_id = %s"
cursor.execute(sql, bid)
result = cursor.fetchone()
return result
def check_goods_exist(self, goods_id):
with self.db.cursor() as cursor:
# cursor = self.db.cursor()
sql = "SELECT 1 FROM szlc.lie_goods WHERE product_id = %s"
cursor.execute(sql, goods_id)
result = cursor.fetchone()
return result
def get_order_info_by_order_id(self, oid):
with self.db.cursor() as cursor:
# cursor = self.db.cursor()
sql = "SELECT 1 FROM lie_szlc_order_info WHERE orderID=%s LIMIT 1"
cursor.execute(sql, oid)
result = cursor.fetchone()
return result
def check_stock_exist(self, sid):
with self.db.cursor() as cursor:
sql = 'SELECT 1 FROM lie_szlc_stock_info WHERE stockId=%s LIMIT 1'
cursor.execute(sql, sid)
result = cursor.fetchone()
return result
def insert_lcsz_stock(self, data):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_szlc_stock_info(stockId, date, productName, productType, productId, encapsulationModel,
providerMode, ctime) VALUES (%(stockId)s, %(date)s, %(productName)s,%(productType)s,
%(productId)s, %(encapsulationModel)s, %(providerMode)s, %(ctime)s)
"""
cursor.execute(sql, data)
self.db.commit()
def update_lcsz_order_list(self, data):
with self.db.cursor() as cursor:
sql = "UPDATE lie_szlc_order_info SET paymentStatus=%s, orderStatus=%s, mtime=%s WHERE orderID=%s"
cursor.execute(sql, data)
self.db.commit()
# cursor.close()
def insert_lcsz_order_list(self, data):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_szlc_order_info(orderID, clientName, clientID, orderTS, totalPrice, paymentStatus,
orderStatus, ctime, mtime) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
"""
# ON DUPLICATE KEY UPDATE paymentStatus=VALUES (paymentStatus), orderStatus=VALUES (orderStatus),
# mtime=VALUES (mtime)
cursor.execute(sql, data)
self.db.commit()
# finally:
# cursor.close()
def insert_lcsz_order_details(self, data):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_szlc_order_goods(productId, orderID, productName, productType, encapsulationModel,
productModel, splitNumber, productPrice, minBatchPrice, ctime, brand_id, brand_name) VALUES
(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
"""
cursor.executemany(sql, data)
self.db.commit()
# cursor.close()
def update_img_by_goods_name(self, img, goods_name):
with self.db.cursor() as cursor:
sql = """
UPDATE lie_goods_merge SET goods_img=%s WHERE goods_name=%s
"""
cursor.execute(sql, (img, goods_name))
self.db.commit()
def get_total_page(self):
with self.db.cursor() as cursor:
sql = "SELECT count(goods_id) AS co FROM lie_goods"
cursor.execute(sql)
result = cursor.fetchone()
if not result[0]:
return
total_pages = result[0] // 100
if total_pages % 100 != 0:
total_pages += 1
return total_pages
def get_first_goods_id(self):
with self.db.cursor() as cursor:
sql = "SELECT goods_id FROM lie_goods ORDER BY goods_id LIMIT 1"
cursor.execute(sql)
result = cursor.fetchone()
return result[0]
def get_total(self):
with self.db.cursor() as cursor:
sql = "SELECT count(goods_id) FROM lie_goods"
cursor.execute(sql)
result = cursor.fetchone()
return result[0]
def get_goods_info_arrow(self, goods_id):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
# sql = "SELECT cat_id, url,ext_fields FROM lie_category WHERE islast=1 LIMIT %s, 100" % start
sql = """
SELECT a.goods_id, a.goods_name, a.goods_sn, a.site_url, a.provider_name, a.pdf_url, b.url referer FROM
lie_goods AS a
INNER JOIN lie_category AS b ON a.cat_id = b.cat_id WHERE a.goods_id > %s ORDER BY a.goods_id
LIMIT 100"""
cursor.execute(sql, goods_id)
result = cursor.fetchall()
return result
def get_goods_info_rs(self, goods_id):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = """
SELECT cat_id, goods_id, goods_name, goods_sn, site_url,
provider_name,goods_desc FROM lie_goods
WHERE goods_id > %s ORDER BY goods_id ASC
LIMIT 200"""
cursor.execute(sql, goods_id)
result = cursor.fetchall()
return result
def get_goods_info_master(self, goods_id):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = """
SELECT goods_id, goods_name, goods_sn, site_url, provider_name
FROM lie_goods
WHERE goods_id > %s ORDER BY goods_id ASC
LIMIT 50"""
cursor.execute(sql, goods_id)
result = cursor.fetchall()
return result
def get_goods_info_verical(self, goods_id):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = """SELECT goods_id, goods_name, goods_sn, pdf_url, goods_brief,
provider_name FROM lie_goods WHERE goods_id >%s ORDER BY goods_id LIMIT 100"""
cursor.execute(sql, goods_id)
result = cursor.fetchall()
return result
# common
def get_cate_count(self):
with self.db.cursor() as cursor:
sql = "SELECT count(*) as co FROM lie_category WHERE parent_id !=0"
cursor.execute(sql)
result = cursor.fetchone()
return result[0]
def get_cate_by_page(self, page):
start = str((page - 1) * 100)
with self.db.cursor() as cursor:
sql = "SELECT cat_id, url FROM lie_category WHERE parent_id != 0 LIMIT %s, 100" % start
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_by_page_avnet(self, page):
start = str((page - 1) * 100)
with self.db.cursor() as cursor:
sql = "SELECT cat_id, url,ext_fields FROM lie_category WHERE islast=1 LIMIT %s, 100" % start
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_by_page_arrow(self, page):
start = str((page - 1) * 100)
with self.db.cursor() as cursor:
sql = "SELECT cat_id, url, cat_name FROM lie_category where islast=1 AND is_show=1 LIMIT %s, 100" % start
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_verical(self):
with self.db.cursor() as cursor:
sql = "SELECT cat_id, url FROM lie_category WHERE islast=1"
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_allied(self):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = "SELECT cat_id, url, cat_name FROM lie_category WHERE islast=1 AND is_show=1"
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_master(self):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = "SELECT cat_id, url, page_count FROM lie_category WHERE islast=1 AND is_show=1"
cursor.execute(sql)
result = cursor.fetchall()
return result
def get_cate_powell(self):
with self.db.cursor(cursor=pymysql.cursors.DictCursor) as cursor:
sql = "SELECT cat_id, url FROM lie_category WHERE islast=1 AND is_show=1"
cursor.execute(sql)
result = cursor.fetchall()
return result
def update_cate_status(self, cat_id):
with self.db.cursor() as cursor:
sql = """
UPDATE lie_category SET is_show = 0 WHERE cat_id = %s
"""
cursor.execute(sql, cat_id)
self.db.commit()
def get_cat_id_by_name(self, name):
with self.db.cursor() as cursor:
sql = "SELECT cat_id FROM lie_category WHERE cat_name=%s"
cursor.execute(sql, name)
result = cursor.fetchone()
result = result[0] if result else None
return result
def insert_cate(self, cate):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_category(cat_name, keywords, parent_id, url, islast, level, ext_fields) VALUES (%s, %s,
%s, %s, %s, %s, %s)
"""
cursor.execute(sql, cate)
self.db.commit()
def insert_cate_2(self, cate):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_category(cat_name, keywords, parent_id, url, islast, level, ext_fields) VALUES (%s, %s,
%s, %s, %s, %s, %s)
"""
cursor.execute(sql, cate)
self.db.commit()
def insert_cate_3(self, cate):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_category(cat_name, keywords, parent_id, url, islast, level, supplier_id) VALUES (%s, %s,
%s, %s, %s, %s, %s)
"""
cursor.execute(sql, cate)
self.db.commit()
def update_cate(self, cate_name, page):
with self.db.cursor() as cursor:
sql = """
UPDATE lie_category SET page_count = %s WHERE cat_name = %s
"""
cursor.execute(sql, (page, cate_name))
self.db.commit()
def get_parent_id(self, name):
with self.db.cursor() as cursor:
sql = "SELECT cat_id FROM lie_category WHERE cat_name = %s"
cursor.execute(sql, name)
result = cursor.fetchone()
result = result[0] if result else None
return result
def get_goods_id_by_goods_sn(self, gs):
with self.db.cursor() as cursor:
sql = "SELECT goods_id FROM lie_goods WHERE goods_sn=%s"
cursor.execute(sql, gs)
result = cursor.fetchone()
result = result[0] if result else None
return result
def get_brand_id_by_brand_name(self, bn):
with self.db.cursor() as cursor:
sql = "SELECT brand_id FROM lie_brand WHERE brand_name=%s"
cursor.execute(sql, (bn,))
result = cursor.fetchone()
result = result[0] if result else 0
return result
def add_goods(self, goods):
with self.db.cursor() as cursor:
goods['add_time'] = self.get_ts()
sql = """
INSERT INTO lie_goods(cat_id, goods_sn, goods_name, goods_name_style, provider_name, brand_id,
goods_number, min_buynum, goods_brief, goods_desc, goods_thumb, goods_img, site_url, pdf_url,
add_time) VALUES
(%(cat_id)s, %(goods_sn)s, %(goods_name)s, %(goods_name_style)s, %(provider_name)s, %(brand_id)s,
%(goods_number)s, %(min_buynum)s, %(goods_brief)s, %(goods_desc)s, %(goods_thumb)s, %(goods_img)s,
%(site_url)s, %(pdf_url)s, %(add_time)s)
"""
cursor.execute(sql, goods)
self.db.commit()
def add_goods_company(self, goods):
with self.db.cursor() as cursor:
goods['add_time'] = self.get_ts()
sql = """
INSERT INTO lie_goods(cat_id, goods_sn, goods_name, goods_name_style, provider_name, brand_id,
goods_number, min_buynum, goods_brief, goods_desc, goods_thumb, goods_img, site_url, pdf_url,
add_time, supplier_id, canal) VALUES
(%(cat_id)s, %(goods_sn)s, %(goods_name)s, %(goods_name_style)s, %(provider_name)s, %(brand_id)s,
%(goods_number)s, %(min_buynum)s, %(goods_brief)s, %(goods_desc)s, %(goods_thumb)s, %(goods_img)s,
%(site_url)s, %(pdf_url)s, %(add_time)s, %(supplier_id)s, %(canal)s)
"""
cursor.execute(sql, goods)
self.db.commit()
def add_brand(self, brand):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_brand(brand_name, site_url, brand_desc) VALUES (%(brand_name)s, %(site_url)s,
%(brand_desc)s)
"""
cursor.execute(sql, brand)
self.db.commit()
def check_price_exist(self, goods_id):
with self.db.cursor() as cursor:
n = str(goods_id)[-1]
sql = "SELECT COUNT(*) FROM lie_goods_price_{} WHERE goods_id=%s".format(n)
cursor.execute(sql, goods_id)
result = cursor.fetchone()
return result[0]
def add_price(self, prices):
with self.db.cursor() as cursor:
n = str(prices['goods_id'])[-1]
sql = "INSERT INTO lie_goods_price_{0}(goods_id, price) VALUES (%(goods_id)s, %(price)s)".format(n)
cursor.execute(sql, prices)
self.db.commit()
def get_attr_id_by_name(self, cate_attr): # (id, name)
with self.db.cursor() as cursor:
sql = "SELECT attr_id FROM lie_category_attr WHERE cat_id=%s AND attr_name=%s"
cursor.execute(sql, cate_attr)
result = cursor.fetchone()
result = result[0] if result else None
return result
def add_cate_attr(self, cate_attr):
with self.db.cursor() as cursor:
sql = "INSERT INTO lie_category_attr(cat_id, attr_name) VALUES (%s, %s)"
cursor.execute(sql, cate_attr)
self.db.commit()
def get_ext_id_by_goods_id_attr_name(self, gi, an):
with self.db.cursor() as cursor:
n = str(gi)[-1]
sql = "SELECT ext_id FROM lie_goods_attr_fields{0} WHERE goods_id=%s AND attr_name=%s".format(n)
cursor.execute(sql, (gi, an))
result = cursor.fetchone()
result = result[0] if result else None
return result
def add_attr(self, ext_data):
with self.db.cursor() as cursor:
n = str(ext_data['goods_id'])[-1]
sql = """
INSERT INTO lie_goods_attr_fields{0}(goods_id, cat_id, attr_id, attr_name, attr_value)VALUES
(%(goods_id)s, %(cat_id)s, %(attr_id)s, %(attr_name)s, %(attr_value)s)""".format(n)
cursor.execute(sql, ext_data)
self.db.commit()
def get_not_img(self, platform, goods_id):
with self.db.cursor() as cursor:
sql = """SELECT id, goods_name FROM lie_goods_merge WHERE goods_img = '' AND supplier_name = %s AND id
> %s ORDER BY id LIMIT 500
"""
cursor.execute(sql, (platform, goods_id))
result = cursor.fetchall()
return result
def update_brand(self, gid, brand):
with self.db.cursor() as cursor:
sql = "UPDATE lie_goods SET provider_name=%s WHERE goods_id=%s"
cursor.execute(sql, (brand, gid))
self.db.commit()
def update_brands(self, gid, brand, brand_id):
with self.db.cursor() as cursor:
sql = "UPDATE lie_goods SET provider_name=%s, brand_id=%s WHERE goods_id=%s"
cursor.execute(sql, (brand, brand_id, gid))
self.db.commit()
def update_status(self, gid, is_delete=1):
with self.db.cursor() as cursor:
sql = "UPDATE lie_goods SET is_delete=%s WHERE goods_id=%s"
cursor.execute(sql, (is_delete, gid))
self.db.commit()
def update_cost(self, gid, cost):
with self.db.cursor() as cursor:
sql = "UPDATE lie_goods SET has_cost=%s WHERE goods_id=%s"
cursor.execute(sql, (cost, gid))
self.db.commit()
# pc
def insert_pc(self, data):
with self.db.cursor() as cursor:
sql = """
INSERT INTO lie_price_relations(goods_id, goods_name, goods_sn, provider_name, add_time, prices,
prices_ori, avg_disparity_usd, avg_disparity_rmb, plat, compare) VALUES
(%(goods_id)s, %(goods_name)s, %(goods_sn)s, %(provider_name)s, %(batch_time)s, %(prices)s,
%(prices_ori)s, %(avg_disparity_usd)s, %(avg_disparity_rmb)s, %(pn)s, %(cp)s)
"""
cursor.execute(sql, data)
self.db.commit()
# element
def update_url(self, gid, url):
with self.db.cursor() as cursor:
sql = "UPDATE lie_goods SET site_url=%s WHERE goods_id=%s"
cursor.execute(sql, (url, gid))
self.db.commit()
# truncate
def truncate_cate(self):
with self.db.cursor() as cursor:
sql = "TRUNCATE lie_category"
cursor.execute(sql)
self.db.commit()
if __name__ == '__main__':
# pass
d = MySqlOperator('chip1stop')
with d.db.cursor() as cursor:
sql = "SELECT goods_id FROM lie_goods WHERE goods_name=%s and goods_name_style=%s"
cursor.execute(sql, ('AD976AR', 'AD01-0000139'))
result = cursor.fetchone()
result = result[0] if result else None
print(result)
# print(d.get_ext_id_by_goods_id_attr_name(18000500790, 'Product Category'))
# data = (('SO180219037', '蔡**', '19**62A', 1519055525, '2018-02-19 23:52:05', 100, '已付3', '好好', '待取货3', 1519055525,
# 2519055525),
# ('SO180219035', '蔡**', '19**62A', 1519055525, '2018-02-19 23:52:05', 100, '衣付3', '好好', '待取货3', 1519055525,
# 2519055525))
# d.insert_lcsz_order_list(data)
# data1 = (
# ('SO180219034_3', 'SO180219037', '91383', '4.7nH ±0.3nH 编带', '高频电感', '0402', 500, 0.019, 0.0118, 1519055525),
# ('SO180219034_4', 'SO180219037', '91383', '4.7nH ±0.3nH 编带', '高频电感', '0402', 500, 0.019, 0.0118, 1519055525),
# )
# d.insert_lcsz_order_details(data1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment