1st commit
This commit is contained in:
11
.idea/Scripts_Python.iml
generated
Normal file
11
.idea/Scripts_Python.iml
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
<?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>
|
||||
4
.idea/encodings.xml
generated
Normal file
4
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
||||
</project>
|
||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
|
||||
<component name="PyCharmProfessionalAdvertiser">
|
||||
<option name="shown" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Scripts_Python.iml" filepath="$PROJECT_DIR$/.idea/Scripts_Python.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
295
.idea/workspace.xml
generated
Normal file
295
.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,295 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="1d94d1f5-a673-4bcf-8751-aee698725a56" 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="FileEditorManager">
|
||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/mysql_fetch_2.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="483">
|
||||
<caret line="35" selection-start-line="35" selection-end-line="35" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$APPLICATION_CONFIG_DIR$/scratches/scratch_7.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="210">
|
||||
<caret line="14" selection-start-line="14" selection-end-line="14" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$APPLICATION_CONFIG_DIR$/scratches/scratch.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="90">
|
||||
<caret line="6" column="46" selection-end-line="6" selection-end-column="46" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/sqlite_fetch.py">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/mysql_insert.py">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
</file>
|
||||
</leaf>
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Python Script" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</component>
|
||||
<component name="IdeDocumentHistory">
|
||||
<option name="CHANGED_PATHS">
|
||||
<list>
|
||||
<option value="$APPLICATION_CONFIG_DIR$/scratches/scratch_7.py" />
|
||||
<option value="$APPLICATION_CONFIG_DIR$/scratches/scratch.py" />
|
||||
<option value="$PROJECT_DIR$/../webapp/app.py" />
|
||||
<option value="$PROJECT_DIR$/../webapp/index.py" />
|
||||
<option value="$PROJECT_DIR$/../webapp/url.py" />
|
||||
<option value="$PROJECT_DIR$/../webapp/http.py" />
|
||||
<option value="$PROJECT_DIR$/mysql_fetch_2.py" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds">
|
||||
<option name="x" value="97" />
|
||||
<option name="y" value="333" />
|
||||
<option name="width" value="1400" />
|
||||
<option name="height" value="652" />
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||
<component name="ProjectView">
|
||||
<navigator proportions="" version="1">
|
||||
<foldersAlwaysOnTop value="true" />
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="Scope" />
|
||||
<pane id="ProjectPane">
|
||||
<subPane>
|
||||
<expand>
|
||||
<path>
|
||||
<item name="Scripts_Python" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="Scripts_Python" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="Scripts_Python" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="Scratches and Consoles" type="1a2a3e82:ScratchProjectViewPane$MyProjectNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
</pane>
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="com.intellij.ide.scratch.LRUPopupBuilder$1/New Scratch File" value="Python" />
|
||||
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
|
||||
</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="$PROJECT_DIR$/../webapp" />
|
||||
</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.mysql_fetch_2">
|
||||
<configuration name="http" type="PythonConfigurationType" factoryName="Python" temporary="true">
|
||||
<module name="Scripts_Python" />
|
||||
<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$/../webapp" />
|
||||
<option name="IS_MODULE_SDK" value="false" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/../webapp/http.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="mysql_fetch_2" type="PythonConfigurationType" factoryName="Python" temporary="true">
|
||||
<module name="Scripts_Python" />
|
||||
<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" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/mysql_fetch_2.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="scratch" type="PythonConfigurationType" factoryName="Python" temporary="true">
|
||||
<module name="Scripts_Python" />
|
||||
<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="$APPLICATION_CONFIG_DIR$/scratches" />
|
||||
<option name="IS_MODULE_SDK" value="false" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$APPLICATION_CONFIG_DIR$/scratches/scratch.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="scratch_7" type="PythonConfigurationType" factoryName="Python" temporary="true">
|
||||
<module name="Scripts_Python" />
|
||||
<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="$APPLICATION_CONFIG_DIR$/scratches" />
|
||||
<option name="IS_MODULE_SDK" value="false" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$APPLICATION_CONFIG_DIR$/scratches/scratch_7.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>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Python.mysql_fetch_2" />
|
||||
<item itemvalue="Python.http" />
|
||||
<item itemvalue="Python.scratch" />
|
||||
<item itemvalue="Python.scratch_7" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="1d94d1f5-a673-4bcf-8751-aee698725a56" name="Default Changelist" comment="" />
|
||||
<created>1551468624690</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1551468624690</updated>
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="97" y="333" width="1400" height="652" extended-state="0" />
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24945612" />
|
||||
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
||||
<window_info id="Favorites" order="2" side_tool="true" />
|
||||
<window_info anchor="bottom" id="Message" order="0" />
|
||||
<window_info anchor="bottom" id="Find" order="1" />
|
||||
<window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.32857144" />
|
||||
<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="bottom" id="Version Control" order="7" />
|
||||
<window_info anchor="bottom" id="Terminal" order="8" />
|
||||
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
|
||||
<window_info anchor="bottom" id="Python Console" order="10" />
|
||||
<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>
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$PROJECT_DIR$/../webapp/app.py" />
|
||||
<entry file="file://$PROJECT_DIR$/../webapp/url.py" />
|
||||
<entry file="file://$PROJECT_DIR$/../webapp/http.py" />
|
||||
<entry file="file://$PROJECT_DIR$/mysql_fetch_2.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="483">
|
||||
<caret line="35" selection-start-line="35" selection-end-line="35" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$APPLICATION_CONFIG_DIR$/scratches/scratch_7.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="210">
|
||||
<caret line="14" selection-start-line="14" selection-end-line="14" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$APPLICATION_CONFIG_DIR$/scratches/scratch.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="90">
|
||||
<caret line="6" column="46" selection-end-line="6" selection-end-column="46" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/../webapp/index.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="285">
|
||||
<caret line="19" selection-start-line="19" selection-end-line="19" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/sqlite_fetch.py">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/mysql_insert.py">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
</component>
|
||||
</project>
|
||||
13
client.py
Normal file
13
client.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import socket
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect(("", 1111))
|
||||
|
||||
print("Le nom du fichier que vous voulez récupérer:")
|
||||
file_name = input(">> ") # utilisez raw_input() pour les anciennes versions python
|
||||
s.send(file_name.encode())
|
||||
file_name = 'Downloads/%s' % (file_name,)
|
||||
r = s.recv(9999999)
|
||||
with open(file_name,'wb') as _file:
|
||||
_file.write(r)
|
||||
print("Le fichier a été correctement copié dans : %s." % file_name)
|
||||
13
fabfile.py
vendored
Normal file
13
fabfile.py
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
from fabric import Connection
|
||||
c = Connection(host='192.168.1.7', user='bruno', port=42666)
|
||||
result = c.run('uname -s')
|
||||
|
||||
|
||||
result = c.put(local='/Users/bruno/test.csv', remote='/homes/bruno')
|
||||
|
||||
# erreur avec local=
|
||||
#result = c.get(remote='/homes/bruno/httpd-vhost.conf', local='/Users/bruno/Downloads/')
|
||||
result = c.get(remote='/homes/bruno/httpd-vhost.conf')
|
||||
|
||||
# erreur avec '/homes/bruno/hello.py'
|
||||
result = c.run('python hello.py')
|
||||
BIN
ma_base.db
Normal file
BIN
ma_base.db
Normal file
Binary file not shown.
30
mysql_fetch.py
Normal file
30
mysql_fetch.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import mysql.connector
|
||||
|
||||
#pip3 install mysql-connector-python
|
||||
|
||||
#pip install mysql
|
||||
#pip install MySQL-python
|
||||
#import MySQLdb
|
||||
|
||||
try:
|
||||
conn = mysql.connector.connect(host="localhost",user="root",password="sncfp1p2", database="python")
|
||||
cursor = conn.cursor()
|
||||
|
||||
name = "olivier"
|
||||
id = 5
|
||||
|
||||
cursor.execute("""SELECT id, name, age FROM visiteurs WHERE name = %s""", (name, ))
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
print('{0} : {1} - {2}'.format(row[0], row[1], row[2]))
|
||||
|
||||
#conn.commit()
|
||||
|
||||
except Exception as e:
|
||||
print("Erreur")
|
||||
conn.rollback()
|
||||
# raise e
|
||||
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
35
mysql_fetch_2.py
Normal file
35
mysql_fetch_2.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import pymysql
|
||||
|
||||
# pip3 install PyMySQL
|
||||
# http://zetcode.com/python/pymysql/
|
||||
|
||||
con = pymysql.connect('localhost', 'root', 'sncfp1p2', 'python')
|
||||
|
||||
with con:
|
||||
|
||||
cursor = con.cursor()
|
||||
|
||||
cursor.execute("SELECT VERSION()")
|
||||
version = cursor.fetchone()
|
||||
print("Database version: {}".format(version[0]))
|
||||
|
||||
name = "bruno"
|
||||
age = 50
|
||||
|
||||
# cursor.execute("""SELECT id, name, age FROM visiteurs WHERE name = %s""", (name, ))
|
||||
cursor.execute("""SELECT id, name, age FROM visiteurs WHERE name = %s AND age = %s""", (name,age))
|
||||
|
||||
rows = cursor.fetchall()
|
||||
for row in rows:
|
||||
print('{0} : {1} - {2}'.format(row[0], row[1], row[2]))
|
||||
|
||||
print("The query affected {} rows".format(cursor.rowcount))
|
||||
|
||||
#age = 35
|
||||
# cursor.execute("""SELECT id, name, age FROM visiteurs WHERE age < %s""", (age))
|
||||
cursor.execute("""SELECT id, name, age FROM visiteurs ORDER BY age LIMIT 1""")
|
||||
jeune = cursor.fetchone()
|
||||
print("Le + jeune : {0} - {1} - {2}".format(jeune[0], jeune[1], jeune[2]))
|
||||
|
||||
print("The query affected {} rows".format(cursor.rowcount))
|
||||
|
||||
42
mysql_insert.py
Normal file
42
mysql_insert.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import mysql.connector
|
||||
|
||||
#pip3 install mysql-connector-python
|
||||
|
||||
#pip install mysql
|
||||
#pip install MySQL-python
|
||||
#import MySQLdb
|
||||
|
||||
try:
|
||||
conn = mysql.connector.connect(host="localhost",user="root",password="sncfp1p2", database="python")
|
||||
cursor = conn.cursor()
|
||||
|
||||
# créer une table
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS visiteurs (
|
||||
id int(5) NOT NULL AUTO_INCREMENT,
|
||||
name varchar(50) DEFAULT NULL,
|
||||
age INTEGER DEFAULT NULL,
|
||||
PRIMARY KEY(id)
|
||||
);
|
||||
""")
|
||||
|
||||
# ajouter des données
|
||||
user = ("bruno", "50")
|
||||
sql = "INSERT INTO visiteurs (name, age) VALUES(%s, %s)"
|
||||
|
||||
#cursor.execute("""INSERT INTO visiteurs (name, age) VALUES(%s, %d)""", user)
|
||||
cursor.execute(sql, user)
|
||||
|
||||
user = {"name": "olivier", "age" : "34"}
|
||||
cursor.execute("""INSERT INTO visiteurs (name, age) VALUES(%(name)s, %(age)s)""", user)
|
||||
|
||||
conn.commit()
|
||||
|
||||
except Exception as e:
|
||||
print("Erreur")
|
||||
conn.rollback()
|
||||
# raise e
|
||||
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
34
server.py
Normal file
34
server.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import socket
|
||||
import threading
|
||||
|
||||
class ClientThread(threading.Thread):
|
||||
|
||||
def __init__(self, ip, port, clientsocket):
|
||||
|
||||
threading.Thread.__init__(self)
|
||||
self.ip = ip
|
||||
self.port = port
|
||||
self.clientsocket = clientsocket
|
||||
print("[+] Nouveau thread pour %s %s" % (self.ip, self.port, ))
|
||||
|
||||
def run(self):
|
||||
|
||||
print("Connexion de %s %s" % (self.ip, self.port, ))
|
||||
|
||||
r = self.clientsocket.recv(2048)
|
||||
print("Ouverture du fichier: ", r, "...")
|
||||
fp = open(r, 'rb')
|
||||
self.clientsocket.send(fp.read())
|
||||
|
||||
print("Client déconnecté...")
|
||||
|
||||
tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
tcpsock.bind(("",1111))
|
||||
|
||||
while True:
|
||||
tcpsock.listen(10)
|
||||
print( "En écoute...")
|
||||
(clientsocket, (ip, port)) = tcpsock.accept()
|
||||
newthread = ClientThread(ip, port, clientsocket)
|
||||
newthread.start()
|
||||
35
sqlite_fetch.py
Normal file
35
sqlite_fetch.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import sqlite3
|
||||
|
||||
try:
|
||||
# si la base n'existe pas, elle est créee automatiquement
|
||||
conn = sqlite3.connect('ma_base.db')
|
||||
|
||||
# Récupérer la 1ere ligne
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""SELECT name, age FROM users""")
|
||||
user1 = cursor.fetchone()
|
||||
print(user1)
|
||||
|
||||
# Récupérer les users dont le nom est joe
|
||||
name = "joe"
|
||||
#id = 3
|
||||
cursor.execute("""SELECT id, name, age FROM users WHERE name=?""", (name,))
|
||||
response = cursor.fetchone()
|
||||
print(response)
|
||||
|
||||
# Récupérer toutes les lignes
|
||||
cursor.execute("""SELECT id, name, age FROM users""")
|
||||
#rows = cursor.fetchall()
|
||||
#for row in rows:
|
||||
for row in cursor:
|
||||
print('{0} : {1} - {2}'.format(row[0], row[1], row[2]))
|
||||
|
||||
except sqlite3.OperationalError:
|
||||
print('Erreur la table existe déjà')
|
||||
except Exception as e:
|
||||
print("Erreur")
|
||||
conn.rollback()
|
||||
# raise e
|
||||
|
||||
finally:
|
||||
conn.close()
|
||||
51
sqlite_insert.py
Normal file
51
sqlite_insert.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import sqlite3
|
||||
|
||||
try:
|
||||
# si la base n'existe pas, elle est créee automatiquement
|
||||
conn = sqlite3.connect('ma_base.db')
|
||||
|
||||
# travailler avec une base temporaire
|
||||
#conn = sqlite3.connect(':memory:')
|
||||
|
||||
# créer une table
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS users(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
name TEXT,
|
||||
age INTERGER
|
||||
)
|
||||
""")
|
||||
conn.commit()
|
||||
|
||||
# ajouter des données
|
||||
cursor.execute("""
|
||||
INSERT INTO users(name, age) VALUES(?, ?)""", ("olivier", 30))
|
||||
|
||||
# ajouter des données depuis un dictionnaire
|
||||
data = {"name" : "bruno", "age" : 50}
|
||||
cursor.execute("""
|
||||
INSERT INTO users(name, age) VALUES(:name, :age)""", data)
|
||||
|
||||
# ajouter des données (plusieurs insert en une seule fois)
|
||||
users = []
|
||||
users.append(("joe", 35))
|
||||
users.append(("jean-louis", 90))
|
||||
cursor.executemany("""
|
||||
INSERT INTO users(name, age) VALUES(?, ?)""", users)
|
||||
|
||||
conn.commit()
|
||||
|
||||
# id de la dernière ligne
|
||||
id = cursor.lastrowid
|
||||
print('dernier id: %d' % id)
|
||||
|
||||
except sqlite3.OperationalError:
|
||||
print('Erreur la table existe déjà')
|
||||
except Exception as e:
|
||||
print("Erreur")
|
||||
conn.rollback()
|
||||
# raise e
|
||||
|
||||
finally:
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user