initial
This commit is contained in:
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
*.pyc
|
||||||
|
*.spec
|
||||||
|
*.toc
|
||||||
|
*.pkg
|
||||||
|
*.zip
|
||||||
|
*.html
|
||||||
|
*.txt
|
||||||
|
*.pyz
|
||||||
|
*.pyo
|
||||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.pythonPath": "/usr/bin/python3.6"
|
||||||
|
}
|
||||||
57
FtpCsvReceiver.py
Executable file
57
FtpCsvReceiver.py
Executable file
@@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import pika
|
||||||
|
import logging
|
||||||
|
from battilo.timefmt import timestamp_fmt as ts
|
||||||
|
|
||||||
|
from pyftpdlib.handlers import FTPHandler
|
||||||
|
from pyftpdlib.servers import FTPServer
|
||||||
|
from pyftpdlib.authorizers import UnixAuthorizer
|
||||||
|
from pyftpdlib.filesystems import UnixFilesystem
|
||||||
|
|
||||||
|
|
||||||
|
class MyHandler(FTPHandler):
|
||||||
|
def on_file_received(self, file):
|
||||||
|
with open(file, "r") as file_csv:
|
||||||
|
for i, line in enumerate(file_csv.readlines(4096), 1):
|
||||||
|
if i == 2:
|
||||||
|
unit_type, unit_name = line.strip('\n').replace(";","").replace(",","").split(" ")
|
||||||
|
logging.info("PID {:>5} >> {} {}".format(os.getpid(), unit_type.upper(), unit_name.upper()))
|
||||||
|
break
|
||||||
|
file_csv.close
|
||||||
|
path, filename_ext = os.path.split(file)
|
||||||
|
filename, file_extension = os.path.splitext(filename_ext)
|
||||||
|
try:
|
||||||
|
os.mkdir(path + '/' + unit_name.upper())
|
||||||
|
logging.info("PID {:>5} >> path {} created.".format(os.getpid(), unit_name.upper()))
|
||||||
|
except FileExistsError:
|
||||||
|
logging.info("PID {:>5} >> path {} already exists.".format(os.getpid(), unit_name.upper()))
|
||||||
|
os.rename(file, path + '/' + unit_name.upper() + '/' + filename + '_' + str(ts.timestamp("tms") + file_extension))
|
||||||
|
|
||||||
|
def on_incomplete_file_received(self, file):
|
||||||
|
# remove partially uploaded files
|
||||||
|
os.remove(file)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
try:
|
||||||
|
authorizer = UnixAuthorizer(
|
||||||
|
rejected_users=["root"], require_valid_shell=True)
|
||||||
|
handler = MyHandler
|
||||||
|
handler.authorizer = authorizer
|
||||||
|
handler.abstracted_fs = UnixFilesystem
|
||||||
|
|
||||||
|
logging.basicConfig(format='%(asctime)s %(message)s',
|
||||||
|
filename='/var/log/ftpCsvRecv.log', level=logging.INFO)
|
||||||
|
|
||||||
|
server = FTPServer(('', 21), handler)
|
||||||
|
|
||||||
|
server.serve_forever()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
logging.info("PID {:>5} >> Error: {}.".format(os.getpid(), "Shutdown requested...exiting"))
|
||||||
|
except Exception:
|
||||||
|
print("{} - PID {:>5} >> Error: {}.".format(ts.timestamp("log"), os.getpid(), sys.exc_info()[1]))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
1
battilo/__init__.py
Normal file
1
battilo/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
"""Utilità"""
|
||||||
0
battilo/parsers/G801_parser.py
Normal file
0
battilo/parsers/G801_parser.py
Normal file
1
battilo/parsers/__init__.py
Normal file
1
battilo/parsers/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
"""Parser delle centraline"""
|
||||||
1
battilo/timefmt/__init__.py
Normal file
1
battilo/timefmt/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
"""Utilità per i formati timestamp"""
|
||||||
9
battilo/timefmt/timestamp_fmt.py
Normal file
9
battilo/timefmt/timestamp_fmt.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
"""Funzioni per timestamp
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
def timestamp(t):
|
||||||
|
fmt = {'log': '%Y-%m-%d %H:%M:%S', 'tms': '%Y%m%d%H%M%S'}
|
||||||
|
return datetime.datetime.now().strftime(fmt[t])
|
||||||
BIN
build/FtpCsvReceiver/FtpCsvReceiver
Executable file
BIN
build/FtpCsvReceiver/FtpCsvReceiver
Executable file
Binary file not shown.
BIN
dist/FtpCsvReceiver
vendored
Executable file
BIN
dist/FtpCsvReceiver
vendored
Executable file
Binary file not shown.
25
receiveSMS.py
Executable file
25
receiveSMS.py
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
|
class
|
||||||
|
|
||||||
|
def main():
|
||||||
|
authorizer = UnixAuthorizer(
|
||||||
|
rejected_users=["root"], require_valid_shell=True)
|
||||||
|
|
||||||
|
#handler = FTPHandler
|
||||||
|
handler = MyHandler
|
||||||
|
handler.authorizer = authorizer
|
||||||
|
handler.abstracted_fs = UnixFilesystem
|
||||||
|
|
||||||
|
logging.basicConfig(format='%(asctime)s %(message)s',
|
||||||
|
filename='/var/log/ftpCsvRecv.log', level=logging.INFO)
|
||||||
|
|
||||||
|
server = FTPServer(('', 21), handler)
|
||||||
|
server.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user