Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
O
oie-year-report-analyse
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
齐昊宇
oie-year-report-analyse
Commits
b166407a
Commit
b166407a
authored
May 21, 2021
by
qihaoyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
结束提交
parent
9d6fc056
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
41 deletions
+130
-41
workspace.xml
.idea/workspace.xml
+105
-24
ana.log
ana.log
+0
-3
main.py
main.py
+22
-8
utils.cpython-36.pyc
postgre/__pycache__/utils.cpython-36.pyc
+0
-0
utils.py
postgre/utils.py
+3
-6
No files found.
.idea/workspace.xml
View file @
b166407a
This diff is collapsed.
Click to expand it.
ana.log
deleted
100644 → 0
View file @
9d6fc056
This diff is collapsed.
Click to expand it.
main.py
View file @
b166407a
from
postgre.utils
import
util
as
pysql
from
postgre.utils
import
util
as
pysql
from
yearly_report_analysis
import
year
from
yearly_report_analysis
import
year
import
re
import
re
import
math
class
Database
():
class
Database
():
html
=
''
html
=
''
res
=
''
res
=
''
count
=
10
count
=
10
start
=
120
start
=
0
length
=
0
year
=
''
year
=
''
country
=
''
country
=
''
type
=
''
type
=
''
...
@@ -81,20 +83,27 @@ class Database():
...
@@ -81,20 +83,27 @@ class Database():
}
# 6
}
# 6
def
__init__
(
self
):
def
__init__
(
self
):
self
.
get_database_table_length
()
self
.
get_disease_list
()
self
.
get_disease_list
()
self
.
get_html
()
#
self.get_html()
self
.
ana_to_json
()
self
.
ana_to_json
()
def
get_database_table_length
(
self
):
data
=
pysql
.
selectData
([
'count(1)'
],
'oie_yearlyreport_new'
)
self
.
length
=
data
[
0
][
'count(1)'
]
def
get_html
(
self
):
def
get_html
(
self
):
self
.
print_and_log
(
'开始获取'
+
str
(
self
.
start
)
+
'后'
+
str
(
self
.
count
)
+
'条'
)
select_res
=
pysql
.
selectData
((
'country_code'
,
'year'
,
'type'
,
'json_text'
,
'id'
),
'oie_yearlyreport_new'
,
False
,
select_res
=
pysql
.
selectData
((
'country_code'
,
'year'
,
'type'
,
'json_text'
,
'id'
),
'oie_yearlyreport_new'
,
False
,
(
self
.
count
,
self
.
start
))
(
self
.
count
,
self
.
start
))
self
.
select_res
=
select_res
self
.
select_res
=
select_res
self
.
print_and_log
(
str
(
self
.
start
)
+
'后'
+
str
(
self
.
count
)
+
'条获取成功,开始解析'
)
def
ana_to_json
(
self
):
def
ana_to_json
(
self
):
self
.
res
=
year
.
analysis
(
self
.
html
)
self
.
res
=
year
.
analysis
(
self
.
html
)
def
analyse_ctrl
(
self
):
def
analyse_ctrl
(
self
):
for
i
in
range
(
10
,
20
):
for
i
in
range
(
0
,
math
.
ceil
(
self
.
length
/
self
.
count
)
):
self
.
get_html
()
self
.
get_html
()
for
j
in
self
.
select_res
:
for
j
in
self
.
select_res
:
self
.
year
=
j
[
'year'
]
self
.
year
=
j
[
'year'
]
...
@@ -112,6 +121,9 @@ class Database():
...
@@ -112,6 +121,9 @@ class Database():
if
i
[
j
][
'no'
]
==
1
:
# summary
if
i
[
j
][
'no'
]
==
1
:
# summary
table_1
=
self
.
handle_a_table_1
(
i
[
j
])
table_1
=
self
.
handle_a_table_1
(
i
[
j
])
self
.
insert_into_1
(
table_1
)
self
.
insert_into_1
(
table_1
)
break
self
.
print_and_log
(
'第'
+
str
(
self
.
start
)
+
'条分析完成 年份:'
+
str
(
self
.
year
)
+
' 国家:'
+
self
.
country
+
' 类型:'
+
self
.
type
)
# print(table_1)
# print(table_1)
# elif i[j]['no'] == 2: # not_report
# elif i[j]['no'] == 2: # not_report
# table_2 = self.handle_a_table_2(i[j]['tables'])
# table_2 = self.handle_a_table_2(i[j]['tables'])
...
@@ -165,10 +177,6 @@ class Database():
...
@@ -165,10 +177,6 @@ class Database():
# elif i[j]['no'] == 16:
# elif i[j]['no'] == 16:
# table_16 = self.handle_a_table_16(i[j])
# table_16 = self.handle_a_table_16(i[j])
# print(table_16)
# print(table_16)
with
open
(
'ana.log'
,
'a'
)
as
fileReader
:
fileReader
.
write
(
'第'
+
str
(
self
.
start
)
+
'条分析完成 年份:'
+
str
(
self
.
year
)
+
' 国家:'
+
self
.
country
+
' 类型:'
+
self
.
type
)
print
(
'第'
+
str
(
self
.
start
)
+
'条分析完成 年份:'
+
str
(
self
.
year
)
+
' 国家:'
+
self
.
country
+
' 类型:'
+
self
.
type
)
def
handle_a_table_1
(
self
,
table
):
def
handle_a_table_1
(
self
,
table
):
auto
=
[
0
,
1
,
2
]
auto
=
[
0
,
1
,
2
]
return
self
.
ana_table_to_ok
(
table
,
auto
)
return
self
.
ana_table_to_ok
(
table
,
auto
)
...
@@ -384,7 +392,7 @@ class Database():
...
@@ -384,7 +392,7 @@ class Database():
else
:
else
:
pysql
.
insertData
({
'oiednameen'
:
disease_name
},
'oie_disease'
)
pysql
.
insertData
({
'oiednameen'
:
disease_name
},
'oie_disease'
)
self
.
get_disease_list
()
self
.
get_disease_list
()
self
.
get_disease_standard_id
(
disease_name
)
return
self
.
get_disease_standard_id
(
disease_name
)
def
get_standard_disease_name
(
self
,
disease_name
):
def
get_standard_disease_name
(
self
,
disease_name
):
disease_name
=
disease_name
.
replace
(
' (Domestic and Wild)'
,
''
)
disease_name
=
disease_name
.
replace
(
' (Domestic and Wild)'
,
''
)
...
@@ -444,6 +452,12 @@ class Database():
...
@@ -444,6 +452,12 @@ class Database():
"'"
,
''
)
"'"
,
''
)
return
k
return
k
def
print_and_log
(
self
,
text
):
print
(
text
)
with
open
(
'ana.log'
,
'a'
)
as
file_write
:
file_write
.
write
(
text
)
file_write
.
write
(
'
\n
'
)
year_report
=
Database
()
year_report
=
Database
()
year_report
.
analyse_ctrl
()
year_report
.
analyse_ctrl
()
postgre/__pycache__/utils.cpython-36.pyc
View file @
b166407a
No preview for this file type
postgre/utils.py
View file @
b166407a
...
@@ -122,13 +122,11 @@ tableInfos = {
...
@@ -122,13 +122,11 @@ tableInfos = {
class
psqlUtil
(
object
):
class
psqlUtil
(
object
):
def
open
(
self
):
def
open
(
self
):
# if not hasattr(self, "conn"):
# 连接到一个给定的数据库
# 连接到一个给定的数据库
self
.
conn
=
psycopg2
.
connect
(
database
=
"animal_new"
,
user
=
"animal"
,
password
=
"animal@9589"
,
host
=
"172.17.1.61"
,
self
.
conn
=
psycopg2
.
connect
(
database
=
"animal_new"
,
user
=
"animal"
,
password
=
"animal@9589"
,
host
=
"172.17.1.61"
,
port
=
"5432"
)
port
=
"5432"
)
# self.conn = psycopg2.connect(database="animal_disease", user="postgres", password="postgres", host="39.104.109.13",
port="5432")
# 建立游标,用来执行数据库操作
# 建立游标,用来执行数据库操作
self
.
cursor
=
self
.
conn
.
cursor
()
self
.
cursor
=
self
.
conn
.
cursor
()
# print("__init__.py", self.conn)
def
close
(
self
):
def
close
(
self
):
# 关闭游标
# 关闭游标
...
@@ -147,11 +145,10 @@ class psqlUtil(object):
...
@@ -147,11 +145,10 @@ class psqlUtil(object):
sql
+=
getValueFromInfo
(
key
,
value
,
tableName
)
+
","
sql
+=
getValueFromInfo
(
key
,
value
,
tableName
)
+
","
sql
=
sql
[
0
:
-
1
:
1
]
sql
=
sql
[
0
:
-
1
:
1
]
sql
+=
")"
sql
+=
")"
# print(sql)
self
.
cursor
.
execute
(
sql
)
self
.
cursor
.
execute
(
sql
)
self
.
conn
.
commit
()
self
.
conn
.
commit
()
def
selectData
(
self
,
fields
,
tableName
,
where
=
False
,
limit
=
False
):
def
selectData
(
self
,
fields
,
tableName
,
where
=
False
,
limit
=
False
):
self
.
open
()
self
.
open
()
sql
=
"SELECT "
sql
=
"SELECT "
for
f
in
fields
:
for
f
in
fields
:
...
...
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