Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update data Add the ability to generate index markdown from the CSV file
- Loading branch information
1 parent
70f07ee
commit dbf6f21
Showing
9 changed files
with
122 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import io | ||
# import pytablewriter | ||
from pytablewriter import JsonTableWriter | ||
import pytablewriter | ||
|
||
def convert(filename, from_ext, to_ext): | ||
input_file = f"{filename}.{from_ext}" | ||
|
||
# writer = pytablewriter.MarkdownTableWriter() | ||
writer = JsonTableWriter() | ||
writer = pytablewriter.JsonTableWriter() | ||
writer.from_csv(input_file) | ||
|
||
with open(f"./src/components/matrix/{filename}.{to_ext}", "w") as f: | ||
writer.stream = f | ||
writer.write_table() | ||
|
||
if __name__ == '__main__': | ||
convert("internships", "csv", "json") | ||
convert("internships", "csv", "json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import pytablewriter | ||
import helpers | ||
|
||
def convert(filename, from_ext, to_ext): | ||
# provide index for the md file | ||
helpers.add_index_col(filename) | ||
|
||
input_file = f"{filename}_temp.{from_ext}" | ||
writer = pytablewriter.MarkdownTableWriter() | ||
writer.from_csv(input_file) | ||
|
||
with open(f"./{filename}.{to_ext}", "w") as f: | ||
writer.table_name = "Internships" | ||
writer.stream = f | ||
writer.write_table() | ||
|
||
# remove the index csv file | ||
os.remove(input_file) | ||
|
||
if __name__ == '__main__': | ||
convert("internships", "csv", "md") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import pandas as pd | ||
import numpy as np | ||
|
||
def add_index_col(filename): | ||
path = f"./{filename}.csv" | ||
df = pd.read_csv(path) | ||
df.sort_values(by=['Name'], inplace=True) | ||
|
||
# make the index col start from 1 | ||
df.index += 1 | ||
df.to_csv(f"./{filename}_temp.csv", index=True, index_label="Index") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
attrs==19.1.0 | ||
beautifulsoup4==4.8.0 | ||
chardet==3.0.4 | ||
DataProperty==0.43.1 | ||
importlib-metadata==0.19 | ||
jsonschema==3.0.1 | ||
mbstrdecoder==0.8.1 | ||
msgfy==0.0.7 | ||
numpy==1.17.0 | ||
pandas==0.25.0 | ||
path.py==12.0.1 | ||
pathvalidate==0.29.0 | ||
pyrsistent==0.15.4 | ||
pytablereader==0.26.1 | ||
pytablewriter==0.46.1 | ||
python-dateutil==2.8.0 | ||
pytz==2019.1 | ||
six==1.12.0 | ||
soupsieve==1.9.2 | ||
tabledata==0.9.1 | ||
typepy==0.6.0 | ||
zipp==0.5.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import pandas as pd | ||
|
||
def sort(filename): | ||
path = f"./{filename}.csv" | ||
df = pd.read_csv(path) | ||
df.sort_values(by=['Name'], inplace=True) | ||
df.to_csv(path, index=False) | ||
|
||
if __name__ == '__main__': | ||
sort("internships") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters