Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8c9cb9

Browse files
author
holmdane
committed
2 parents 5ffbb6f + 82707c8 commit c8c9cb9

6 files changed

Lines changed: 148 additions & 30 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

22
DJITelloPy/
3+
.vscode/settings.json

P2 - Project/copyfilefromfolder.py

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import sqlite3 as lite #importing sqlite (database)
2+
import sys #importing module that gives access to computer system
3+
import os, shutil #importing os module that allows us to use operating system dependent functionality
4+
#importing shutil that allows file copying and/or removing.
5+
from datetime import datetime #importing module enabling us to see the date and time.
6+
import os.path #importing pathname manipulations
7+
import time #importing time module so we can make the programme sleep for a certain amount of secs.
8+
9+
# Create a version of the database in database file (.db)
10+
DB_NAME = "mydatabase.db"
11+
con = lite.connect(DB_NAME)
12+
#creating a datetime variable, with timezone = none.
13+
datetime.now(tz=None)
14+
15+
#defining a function with variables that allow us create variables
16+
def dbFileInsert(tableName, fileName, filePath):
17+
# Creates the SQLite cursor that is used to query the database
18+
cur = con.cursor()
19+
#Executing the desired database script
20+
cur.executescript("""
21+
DROP TABLE IF EXISTS """ + tableName + """;
22+
CREATE TABLE """ + tableName + """ (fileName TEXT, filePath TEXT);
23+
INSERT INTO """ + tableName + """ VALUES('""" + fileName + """','""" + filePath + """');
24+
""")
25+
26+
27+
# Force the database to make changes with the commit command
28+
con.commit()
29+
30+
# Execute simple SQL query
31+
cur.execute('SELECT * FROM '+ tableName)
32+
for i in cur:
33+
print("\n")
34+
for j in i:
35+
print(j)
36+
37+
38+
# Close the database
39+
con.close()
40+
41+
42+
def fileCopy(fileName, fileFrom, fileTo):
43+
os.chdir('C:\\')
44+
print("Changing directionary to the C-drive...")
45+
os.path.isfile(fileTo)
46+
os.path.isfile(fileTo+"\\"+fileName)
47+
48+
# attempting to create a new folder.. if the folder already exists, the programme proceeds to execute the next step
49+
if os.path.exists(fileTo) == False:
50+
os.system('mkdir NyFiskeFolder')
51+
print("Creating new folder...")
52+
elif os.path.exists(fileTo) == True:
53+
print("The folder already exists. Trying to copy image...")
54+
time.sleep(2)
55+
56+
#copying image from old folder to newly created folder and prints the time, unless already exists.
57+
if os.path.exists(fileTo+"\\"+fileName) == False:
58+
shutil.copy(fileFrom+"\\"+fileName,fileTo+"\\"+fileName)
59+
shutil.copy(fileFrom+"\\"+fileName,fileTo+"\\"+fileName)
60+
dateTimeObj = datetime.now()
61+
print("Image has been copied to new folder at this time: ", dateTimeObj)
62+
elif os.path.exists(fileTo+"\\"+fileName) == True:
63+
print("The image has already been copied!")
64+
65+
66+
#calling the functions with the desired variables
67+
dbFileInsert("Images", r"fisk1.jpg", r"\content\images")
68+
69+
fileCopy("fisk1.jpg",r"C:\\FiskeFolder",r"C:\\NyFiskeFolder")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
# Imported liberaies
3+
import threading, socket, time
4+
5+
# Varialbes
6+
FORMAT = 'utf-8'
7+
HEADER = 64
8+
PORT = 9000
9+
DISCONNECT_MSG = '!disconnect'
10+
TELLO_ADDR = ('192.168.10.1', 8889)
11+
SERVER_IP = socket.gethostbyname(socket.gethostname()) # gets IP address of this device
12+
ADDR = (SERVER_IP, PORT)
13+
14+
15+
# UDP and TCP socket
16+
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
17+
tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
18+
tcp_socket.bind(ADDR)
19+
20+
# Functions
21+
def tcp_client(conn, addr):
22+
23+
connected = True
24+
while connected:
25+
msg_length = conn.recv(HEADER).decode(FORMAT)
26+
if msg_length:
27+
msg_length = int(msg_length)
28+
msg = conn.recv(msg_length).decode(FORMAT)
29+
if msg == DISCONNECT_MSG:
30+
connected = False
31+
32+
print(f"[{addr}] {msg}")
33+
conn.send("Msg received".encode(FORMAT))
34+
35+
conn.close()
36+
print(f"[ACTIVE CONNECTIONS] {threading.activeCount() - 1}")
37+
38+
39+
def start():
40+
tcp_socket.listen()
41+
print(f'\n[LISTENING] TCP server is listing on {SERVER_IP} and port {PORT}')
42+
43+
while True:
44+
conn, addr = tcp_socket.accept()
45+
thread = threading.Thread(target=tcp_client, args=(conn, addr))
46+
thread.start()
47+
print(f'\n[CONNECTED] User {addr} has connected to the server')
48+
print(f"[ACTIVE CONNECTIONS] {threading.activeCount() - 1}")
49+
50+
51+
# Here the relay box are being initialized
52+
print('[STARTING] server is starting')
53+
time.sleep(3)
54+
start()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import socket
2+
3+
HEADER = 64
4+
PORT = 9000
5+
FORMAT = 'utf-8'
6+
DISCONNECT_MESSAGE = "!DISCONNECT"
7+
SERVER = "192.168.1.127"
8+
ADDR = (SERVER, PORT)
9+
10+
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
11+
client.connect(ADDR)
12+
13+
def send(msg):
14+
message = msg.encode(FORMAT)
15+
msg_length = len(message)
16+
send_length = str(msg_length).encode(FORMAT)
17+
send_length += b' ' * (HEADER - len(send_length))
18+
client.send(send_length)
19+
client.send(message)
20+
print(client.recv(2048).decode(FORMAT))
21+
22+
while True:
23+
msg = input()
24+
send(msg)

mydatabase.db

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)