Skip to content

Commit

Permalink
minor refactring
Browse files Browse the repository at this point in the history
  • Loading branch information
dulvui committed Aug 7, 2024
1 parent e38ca9f commit 2a3fa05
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ config_version=5
[application]

config/name="SFSCON PDF Downloader"
run/main_scene="res://src/Main.tscn"
run/main_scene="res://src/main.tscn"
config/features=PackedStringArray("4.2", "GL Compatibility")
config/icon="res://icon.svg"

Expand Down
2 changes: 1 addition & 1 deletion app/script_templates/Node/with_header.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ func _ready() -> void:


func _process(delta: float) -> void:
pass
pass
54 changes: 31 additions & 23 deletions app/src/Main.gd → app/src/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var include_title: bool
var include_time: bool
var include_special_characters: bool


func _ready() -> void:
regex.compile("\\w+")

Expand All @@ -81,6 +82,16 @@ func _ready() -> void:
_update_example()


func _process(delta: float) -> void:
if counter_done < counter_pdf:
progress_label.text = "Downloading %d of %d..."%[counter_done, counter_pdf]
elif counter_pdf == 0:
progress_label.text = "No PDF generated, probably somehting went wrong.\nPlease restart."
else:
progress_label.text = "Finished! Happy SFSCON :-)"
progress_bar.value = counter_done


func _load_config() -> void:
config = ConfigFile.new()
config.load("user://settings.cfg")
Expand All @@ -99,16 +110,6 @@ func _save_config(path: String) -> void:
config.save("user://settings.cfg")


func _process(delta: float) -> void:
if counter_done < counter_pdf:
progress_label.text = "Downloading %d of %d..."%[counter_done, counter_pdf]
elif counter_pdf == 0:
progress_label.text = "No PDF generated, probably somehting went wrong.\nPlease restart."
else:
progress_label.text = "Finished! Happy SFSCON :-)"
progress_bar.value = counter_done


func _on_submit_pressed() -> void:
file_dialog.show()

Expand All @@ -117,6 +118,15 @@ func _on_website_file_dialog_file_selected(path: String) -> void:
settings.hide()
_save_config(path.get_base_dir())

_read_csv(path)
_assign_day_mapping()

_download_pdfs()

result.show()


func _read_csv(path: String) -> void:
var file:FileAccess = FileAccess.open(path, FileAccess.READ)

# search for key index values on header row
Expand All @@ -137,14 +147,10 @@ func _on_website_file_dialog_file_selected(path: String) -> void:
if _is_approved(line):
var pdf_link: String = line[keys_index[PDF_LINK_KEY]]
var title: String = line[keys_index[TITLE_KEY]]

var date: String = line[keys_index[DATE_KEY]]
# hotfix for wrong date format 10:3010/11/2023
if date.length() > 10:
date = date.substr(5)

counter_total += 1

if pdf_link.begins_with("https://www.sfscon.it/wp-content/uploads/"):
data[id] = {}
data[id]["pdf_link"] = pdf_link
Expand All @@ -159,8 +165,9 @@ func _on_website_file_dialog_file_selected(path: String) -> void:
errors.append_text(str(errors.get_line_count()) + ") " + title + "\n")
else:
data.erase(id)
print("not approved ", line[keys_index[TITLE_KEY]])



func _assign_day_mapping() -> void:
# TREMENDOUS HACK, don't try this at home, these stunts are performed by trained professionals
# convert date into day 1, day 2, day 3...
var dates_unix: Array[int] = []
Expand Down Expand Up @@ -194,15 +201,12 @@ func _on_website_file_dialog_file_selected(path: String) -> void:
var talk: Dictionary = data[talk_id]
var date: String = talk["date"]
talk["day"] = day_mapping[date]

progress_bar.max_value = counter_pdf
statistics_label.text = "Total: %d - Pdf: %d - No Pdf: %d"%[counter_total, counter_pdf, counter_total - counter_pdf]
_download_pdfs()

result.show()


func _download_pdfs() -> void:
progress_bar.max_value = counter_pdf
statistics_label.text = "Total: %d - Pdf: %d - No Pdf: %d"%[counter_total, counter_pdf, counter_total - counter_pdf]

for id in data.keys():
if data[id].has("pdf_link") and data[id]["pdf_link"].begins_with("https://www.sfscon.it/wp-content/uploads/"):
if http.request_completed.is_connected(_request_completed):
Expand Down Expand Up @@ -331,3 +335,7 @@ func _format_file_name(time: String, title: String, speaker: String) -> String:
func _is_valid_date(date: String) -> bool:
var time: int = Time.get_unix_time_from_datetime_string(date)
return time > 0


func _on_close_pressed():
get_tree().quit()
4 changes: 2 additions & 2 deletions app/src/Main.tscn → app/src/main.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dpmylgddcilwg"]

[ext_resource type="Script" path="res://src/Main.gd" id="1_3qsph"]
[ext_resource type="Script" path="res://src/main.gd" id="1_3qsph"]

[node name="Main" type="Control"]
layout_mode = 3
Expand Down Expand Up @@ -29,7 +29,7 @@ theme_override_constants/separation = 5

[node name="Welcome" type="Label" parent="Settings"]
layout_mode = 2
text = "WELCOME TO THE SFSCON PDF TOOL!"
text = "SFSCON PDF Downloader"
horizontal_alignment = 1

[node name="HSeparator" type="HSeparator" parent="Settings"]
Expand Down

0 comments on commit 2a3fa05

Please sign in to comment.