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

Add workflow to make table #1

Merged
merged 1 commit into from Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/website.py
@@ -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>""")
# %%
22 changes: 22 additions & 0 deletions .github/workflows/website.yml
@@ -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