Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort table items by Year #57

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions scripts/toml_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def toml_to_markdown(toml_string):
index = 1
md_table_entry=""
item_index = 0
for item in list(toml_dict.items())[index:]:
sorted_data_list = sorted(list(toml_dict.items())[index:], key=lambda x: int(x[1]['Year']) if x[1]['Year'].isdigit() else 0, reverse=True)
for item in sorted_data_list:
title, game_info = item
developer = game_info["Developer"]
engine = game_info["Engine"]
Expand Down Expand Up @@ -142,10 +143,10 @@ def markdown_to_dict(file):
markdown_text = file.read()

game_info_dict = {}
table_pattern = r'\|(.+)\|'
table_pattern = r'\|(.+)\|'
table_matches = re.findall(table_pattern, markdown_text, re.MULTILINE)
table_data = table_matches[2:]

for row in table_data:
game_info = [cell.strip() for cell in row.split('|')]
title, developer, engine, year, analysis_raw = game_info
Expand All @@ -164,7 +165,7 @@ def toml_to_dict(toml_string):
toml_dict = toml.loads(toml_string)
del toml_dict["title"]
return toml_dict

def check_change(olddict, newdict):
for title, game_info in newdict.items():
old_game_info = olddict.get(title)
Expand All @@ -178,7 +179,7 @@ def check_change(olddict, newdict):
return True
else:
return True

return False

if __name__ == "__main__":
Expand Down
Loading