-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from KordingLab/add-website-builder
Add workflow to make table
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#%% | ||
# !pip3 install pandas | ||
import pandas as pd | ||
import re | ||
|
||
def to_link_if_markdown(cell_text: str) -> str: | ||
# Matches [alt](url) with regex and converts to html <a>: | ||
cell_text = re.sub(r'\[(.*?)\]\((.*?)\)', r'<a href="\2">\1</a>', cell_text) | ||
return cell_text | ||
|
||
text = open("../../README.md", "r").readlines() | ||
table = [] | ||
# | Year | Paper | Topic | Animal | Model? | Data? | Image/Video Count | | ||
for line in text: | ||
# If line has the correct number of columns | ||
if len(re.findall("\|", line)) == 8: | ||
table.append(line.split("|")[1:-1]) | ||
table = pd.DataFrame(table[2:], columns=table[0]) | ||
|
||
# Substitutions: | ||
table = table.applymap(to_link_if_markdown) | ||
|
||
|
||
# %% | ||
with open("index.html", "w") as f: | ||
f.write("""<html> | ||
<head> | ||
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script> | ||
<link rel="stylesheet" href="https://cdn.datatables.net/2.0.2/css/dataTables.dataTables.css" /> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css"> | ||
<script src="https://cdn.datatables.net/2.0.2/js/dataTables.js"></script> | ||
</head> | ||
<body> | ||
<h1>Awesome Computational Primatology</h1> | ||
<h3>Parodi et al., 2024</h3> | ||
""") | ||
f.write(table.to_html(table_id="table", escape=False, index=False)) | ||
f.write("""<script>$(document).ready( function () { | ||
$('#table').DataTable({ | ||
paging: false | ||
}); | ||
} );</script> | ||
</body> | ||
</html>""") | ||
# %% |
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 @@ | ||
name: Build Website | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.x | ||
- name: Install dependencies | ||
run: pip install pandas | ||
- name: Run website.py | ||
run: python .github/workflows/website.py | ||
- uses: stefanzweifel/git-auto-commit-action@v5 |