Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
USDB Downloader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSR VI
FSR Projekte
USDB Downloader
Commits
e319e314
Verified
Commit
e319e314
authored
1 year ago
by
kjk
Browse files
Options
Downloads
Patches
Plain Diff
hjd
parent
db2e8f31
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
update_db.py
+19
-14
19 additions, 14 deletions
update_db.py
with
19 additions
and
14 deletions
update_db.py
+
19
−
14
View file @
e319e314
import
os
import
os
import
psycopg2
import
psycopg2
import
logging
import
logging
import
concurrent.futures
import
UltraStarSongFileParser
import
UltraStarSongFileParser
from
UltraStarSongFile
import
UltraStarSongFile
from
UltraStarSongFile
import
UltraStarSongFile
...
@@ -9,26 +11,29 @@ def add_directory(path, connection_string):
...
@@ -9,26 +11,29 @@ def add_directory(path, connection_string):
"""
"""
Parse text files in each subdirectory of the given PATH and add the parsed data to the PostgreSQL database using CONNECTION_STRING.
Parse text files in each subdirectory of the given PATH and add the parsed data to the PostgreSQL database using CONNECTION_STRING.
"""
"""
parser
=
UltraStarSongFileParser
.
UltraStarSongFileParser
(
strict_mode
=
False
)
with
concurrent
.
futures
.
ThreadPoolExecutor
()
as
executor
:
futures
=
[]
for
subdir
in
os
.
listdir
(
path
):
subdir_path
=
os
.
path
.
join
(
path
,
subdir
)
# Iterate through each subdirectory in the specified path
if
os
.
path
.
isdir
(
subdir_path
):
for
subdir
in
os
.
listdir
(
path
):
text_files
=
[
f
for
f
in
os
.
listdir
(
subdir_path
)
if
f
.
endswith
(
"
.txt
"
)]
subdir_path
=
os
.
path
.
join
(
path
,
subdir
)
if
os
.
path
.
isdir
(
subdir_path
)
:
if
len
(
text_files
)
==
1
:
# Find the text file within each subdirectory
file_path
=
os
.
path
.
join
(
subdir_path
,
text_files
[
0
])
text_files
=
[
f
for
f
in
os
.
listdir
(
subdir_path
)
if
f
.
endswith
(
"
.txt
"
)]
futures
.
append
(
executor
.
submit
(
process_directory
,
file_path
,
connection_string
))
if
len
(
text_files
)
==
1
:
# Wait for all tasks to complete
file_path
=
os
.
path
.
join
(
subdir_path
,
text_files
[
0
]
)
concurrent
.
futures
.
wait
(
futures
)
logging
.
debug
(
f
"
parsing:
{
file_path
}
"
)
# Parse the text file
parsed_data
=
parser
.
parse_file
(
file_path
)
# Add the parsed data to the PostgreSQL database
def
process_directory
(
file_path
,
connection_string
):
add_to_database
(
connection_string
,
parsed_data
)
parser
=
UltraStarSongFileParser
(
strict_mode
=
False
)
logging
.
debug
(
f
"
parsing:
{
file_path
}
"
)
parsed_data
=
parser
.
parse_file
(
file_path
)
add_to_database
(
connection_string
,
parsed_data
)
def
add_to_database
(
connection_string
,
song_instance
:
UltraStarSongFile
):
def
add_to_database
(
connection_string
,
song_instance
:
UltraStarSongFile
):
"""
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment