use this ! https://inloop.github.io/sqlite-viewer/
In [ ]:
SOCKETS
In [ ]:
#!/usr/bin/python # This is server.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection.
while True:
print 'looping'
c, addr = s.accept() # Establish connection with client.
print 'Got connection from', addr
c.send('Thank you for connecting')
c.close() # Close the connection
break
In [ ]:
#!/usr/bin/python # This is client.py file
import socket # Import socket module
s = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
print 'connecting'
s.connect((host, port))
print s.recv(1024)
s.close # Close the socket when done
setup_db.py
In [1]:
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE location
(id_location text, location text)''')
c.execute('''CREATE TABLE files
(id_location text, id_file text)''')
c.execute('''CREATE TABLE file_info
(id_file text, file_name text, file_size text, creation_time text, file_md5 text)''')
# Save (commit) the changes
conn.commit()
# Close the connection
# => any change that has not been commited will be lost
conn.close()
add_files.py
In [2]:
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
import os
import hashlib
import time
def get_file_md5(filePath):
h = hashlib.md5()
h.update(open(filePath,"rb").read())
return h.hexdigest()
def get_file_sha256(filePath):
h = hashlib.sha256()
h.update(open(filePath,"rb").read())
return h.hexdigest()
def get_dir_data(dir_path):
dir_path = os.path.realpath(dir_path)
#print next(os.walk(dir_path))[2]
#print os.path.basename(dir_path)
id_location = 0
id_file = 0
for dir_file in next(os.walk(dir_path))[2]:
file_name = dir_file
file_md5 = get_file_md5(dir_file)
file_sha256 = get_file_sha256(dir_file)
file_size = os.path.getsize(dir_file)
file_time = time.gmtime(os.path.getctime(dir_file))
file_formatted_time = time.strftime("%Y-%m-%d %I:%M:%S %p", file_time)
file_path = os.path.realpath(dir_file)
location_values = (id_location, file_path)
c.execute("INSERT INTO location VALUES (?, ?)", location_values)
files_values = (id_location, id_file)
c.execute("INSERT INTO files VALUES (?, ?)", files_values)
file_info_values = (id_file, file_name, file_size, file_formatted_time, file_md5)
c.execute("INSERT INTO file_info VALUES (?, ?, ?, ?, ?)", file_info_values)
id_location += 1
id_file += 1
get_dir_data('./')
# Save (commit) the changes
conn.commit()
conn.close()
query_db.py
In [3]:
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
print('\n\n*****location table****\n')
'''
for row in c.execute('SELECT * FROM location'):
# print(c.fetchall())
print(row)
'''
'''
c.execute('SELECT * FROM location')
print(c.fetchall())
'''
c.execute('SELECT * FROM location')
copy = c.fetchall()
for row in copy:
print row
print('\n\n*****files table****\n')
c.execute('SELECT * FROM files')
copy = c.fetchall()
for row in copy:
print row
print('\n\n*****file_info table****\n')
c.execute('SELECT * FROM file_info')
copy = c.fetchall()
for row in copy:
print row
conn.close()
In [13]:
import urllib
import re
params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query?%s" % params)
respData = f.read()
#print respData
count = 0
paragraphs = re.findall(r'<a .*>(.*)</a>',str(respData))
for eachP in paragraphs:
print(eachP)
if count == 5:
break
count += 1
In [ ]: