Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
python_resolve_data
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a111bf69
authored
Aug 29, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add script
parent
2bf6ec2a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
17 deletions
chip1stop.py
chip1stop.py
View file @
a111bf69
...
...
@@ -3,6 +3,7 @@ import datetime
import
ftplib
import
gzip
import
json
import
logging
import
os
import
sys
...
...
@@ -13,17 +14,20 @@ user = "ansetchip1"
password
=
"nf6l2g17"
port
=
21
"""
ftp服务器上文件名的规律 csv文件都是 带时间的
csv文件带有时间
txt文件都是固定文件名
此脚本每天晚上 23:40运行 用于解析当天上传的文件
目前看 RMB接口有两个文件
此脚本每天晚上 23:00运行 用于解析前一天的数据
"""
ftp_remote_path_csv
=
"/Chip1Stop_TI_included_"
+
datetime
.
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d"
)
+
"_ETCHIPS.csv.gz"
ftp_remote_path_txt
=
"/Chip1StopStockList_TI_in_ RMB_Anjie_RMB.txt.gz"
log_path
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
+
"/logs"
+
"/run.log"
logging
.
basicConfig
(
level
=
logging
.
INFO
,
filename
=
log_path
,
format
=
'
%(asctime)
s -
%(filename)
s[line:
%(lineno)
d] -
%(levelname)
s:
%(message)
s'
)
data_str
=
(
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
days
=-
1
))
.
strftime
(
"
%
Y
%
m
%
d"
)
ftp_remote_path_csv
=
"/Chip1Stop_TI_included_"
+
data_str
+
"_ETCHIPS.csv.gz"
ftp_remote_path_txt
=
"/Chip1StopStockList_TI_in_ RMB_Anjie_RMB.txt.gz"
file_local_path_csv
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
+
"/tmp"
+
ftp_remote_path_csv
.
replace
(
".gz"
,
""
)
file_local_path_txt
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
+
"/tmp"
+
ftp_remote_path_txt
.
replace
(
".gz"
,
""
)
file_local_path_csv
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
+
"/tmp"
+
ftp_remote_path_csv
file_local_path_txt
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
+
"/tmp"
+
ftp_remote_path_txt
ENV
=
"test"
# ENV 取值 test 或 prod
...
...
@@ -172,7 +176,7 @@ class DataUtil:
item
[
"price_cn"
]
=
float
(
0
)
table
[
"ladder_price"
]
.
append
(
item
)
ans
=
json
.
dumps
(
table
)
print
(
ans
)
logging
.
info
(
ans
)
def
handle_txt
(
self
,
file_path
):
if
not
os
.
path
.
exists
(
file_path
):
...
...
@@ -247,7 +251,8 @@ class DataUtil:
item
[
"price_cn"
]
=
float
(
ladder_prices
[
"price-usd-"
+
str
(
k
)])
table
[
"ladder_price"
]
.
append
(
item
)
ans
=
json
.
dumps
(
table
)
print
(
ans
)
logging
.
info
(
ans
)
class
Producer
:
...
...
@@ -289,11 +294,35 @@ if __name__ == '__main__':
else
:
print
(
"parameter error."
)
exit
(
1
)
u
=
DataUtil
()
# u.download(ftp_remote_path_csv, file_local_path_csv)
# u.ungz(file_local_path_csv)
# u.download(ftp_remote_path_txt, file_local_path_txt)
# u.ungz(file_local_path_txt)
# u.handle_txt(file_local_path_txt.replace(".gz", ""))
# u.handle_txt(file_local_path_txt.replace(".gz", ""))
print
(
"haha"
)
"""处理csv文件"""
try
:
u
=
DataUtil
()
u
.
download
(
ftp_remote_path_csv
,
file_local_path_csv
)
u
.
ungz
(
file_local_path_csv
)
u
.
handle_csv
(
file_local_path_csv
.
replace
(
".gz"
,
""
))
except
Exception
as
e
:
logging
.
error
(
e
)
finally
:
if
os
.
path
.
exists
(
file_local_path_csv
.
replace
(
".gz"
,
""
)):
os
.
remove
(
file_local_path_csv
.
replace
(
".gz"
,
""
))
"""处理txt文件"""
try
:
u
=
DataUtil
()
u
.
download
(
ftp_remote_path_txt
,
file_local_path_txt
)
u
.
ungz
(
file_local_path_txt
)
u
.
handle_txt
(
file_local_path_txt
.
replace
(
".gz"
,
""
))
except
Exception
as
e
:
logging
.
error
(
e
)
finally
:
if
os
.
path
.
exists
(
file_local_path_txt
.
replace
(
".gz"
,
""
)):
os
.
remove
(
file_local_path_txt
.
replace
(
".gz"
,
""
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment