diff --git a/.github/deploy-ghpages.sh b/.github/deploy-ghpages.sh index afa18bb..867c377 100755 --- a/.github/deploy-ghpages.sh +++ b/.github/deploy-ghpages.sh @@ -14,6 +14,7 @@ siteSource="$1" if [ ! -d "$siteSource" ] then echo "Usage: $0 " + exit 1 fi diff --git a/.github/deploy-readme.sh b/.github/deploy-readme.sh index ee67544..d9b6858 100755 --- a/.github/deploy-readme.sh +++ b/.github/deploy-readme.sh @@ -1,6 +1,6 @@ #!/bin/sh -if [ $CIRCLE_BRANCH != "master" ] +if [ "$GITHUB_REF" != "refs/heads/master" ] then exit fi diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml new file mode 100644 index 0000000..5dfbfaa --- /dev/null +++ b/.github/workflows/build-deploy.yml @@ -0,0 +1,83 @@ +name: build-deploy + +on: + push: + branches: + - master +env: + GH_TOKEN: xxxxd4ef + PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }} + CUSTOM_DOMAIN: awesome.video + GIT_DISCOVERY_ACROSS_FILESYSTEM: 1 +jobs: + awesomebot: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 'latest' + + - name: Install awesome_bot + run: gem install awesome_bot + + - name: Run awesome_bot + run: awesome_bot contents.json --allow-ssl --allow-redirect -a 403,503 + + json-validate: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 'latest' + + - name: Install json-spec + run: pip install json-spec + + - name: Run JSON validate + run: json validate --schema-file=.github/schema.json --document-file=contents.json + + deploy-awesome-video: + runs-on: ubuntu-latest + needs: [awesomebot, json-validate] + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Ruby, Node, and Python + uses: actions/setup-node@v2 + with: + node-version: 'latest' + - name: Install Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 'latest' + - name: Install Python + uses: actions/setup-python@v2 + with: + python-version: 'latest' + + - name: Run README.md gen + run: ruby .github/convert.rb + + - name: Run database.json gen + run: node .github/upgradeDb.js + + - name: Copy README to docs for site gen + run: cp README.md docs/index.md + + - name: Run static site gen + run: mkdocs build + + - name: Deploy new README + run: .github/deploy-readme.sh + + - name: Deploy GitHub Pages + run: .github/deploy-ghpages.sh site diff --git a/.github/workflows/build.yml b/.github/workflows/build-old.yml similarity index 89% rename from .github/workflows/build.yml rename to .github/workflows/build-old.yml index 1f8bc4b..8932020 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build-old.yml @@ -57,9 +57,9 @@ jobs: run: node .github/upgradeDb.js - name: install mkdoc build deps run: sudo apt-get update && sudo apt-get -y install lsb-release unzip python3-pip python3-dev && pip3 install mkdocs mkdocs-material json-spec - - name: run copy readme to docs for site gen - run: cp README.md docs/index.md - - name: run static site gen - run: mkdocs build + - name: use makefile to install all deps to ensure we have the same versions + run: make site_install + - name: use makefile to install all deps to ensure we have the same versions + run: make site_build - name: Deploy docs uses: mhausenblas/mkdocs-deploy-gh-pages@master diff --git a/alm.py b/alm.py new file mode 100644 index 0000000..999c588 --- /dev/null +++ b/alm.py @@ -0,0 +1,106 @@ +from flask import Flask, request, redirect, url_for +from flask_sqlalchemy import SQLAlchemy +from flask_admin import Admin +from flask_admin.contrib.sqla import ModelView +import requests +import json +import base64 +from bs4 import BeautifulSoup + +# Flask Setup +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///awesomeness.db' +app.config['SECRET_KEY'] = 'mysecret' + +# Database Setup +db = SQLAlchemy(app) + +# Flask-Admin Setup +admin = Admin(app, name='AwesomeList Admin', template_mode='bootstrap3') + +# Models +class Link(db.Model): + id = db.Column(db.Integer, primary_key=True) + url = db.Column(db.String(150), unique=True, nullable=False) + name = db.Column(db.String(100)) + description = db.Column(db.String(300)) + +# Add administrative views +admin.add_view(ModelView(Link, db.session)) + +def extract_metadata(url): + try: + response = requests.get(url) + if response.status_code == 200: + soup = BeautifulSoup(response.content, 'html.parser') + title = soup.find('title').text if soup.find('title') else 'No Title' + meta_description = soup.find('meta', attrs={'name': 'description'}) + og_description = soup.find('meta', attrs={'property': 'og:description'}) + if meta_description and meta_description.get('content'): + description = meta_description['content'] + elif og_description and og_description.get('content'): + description = og_description['content'] + else: + description = 'No Description' + return { + 'title': title, + 'description': description, + } + except requests.RequestException: + return None + +def generate_readme(): + links = Link.query.all() + readme_content = "# Awesome Video\\n\\nA curated list of awesome video resources.\\n\\n" + for link in links: + readme_content += f"- [{link.name}]({link.url}) - {link.description}\\n" + return readme_content + +def get_repo_contents_sha(): + url = f'https://api.github.com/repos/krzemienski/awesome-video/contents/README.md' + headers = {'Authorization': 'token your_github_token'} + response = requests.get(url, headers=headers) + if response.status_code == 200: + return response.json().get('sha') + return None + +def update_github_readme(readme_content): + sha = get_repo_contents_sha() + if not sha: + print("Error: Unable to fetch README metadata") + return False + url = f'https://api.github.com/repos/krzemienski/awesome-video/contents/README.md' + headers = {'Authorization': 'token your_github_token'} + data = { + "message": "Update README.md", + "content": base64.b64encode(readme_content.encode()).decode(), + "sha": sha + } + response = requests.put(url, headers=headers, data=json.dumps(data)) + if response.status_code == 200: + print("README updated successfully") + return True + else: + print(f"Error: {response.content}") + return False + +@app.route('/submit', methods=['POST']) +def submit_url(): + data = request.json + url = data.get('url') + metadata = extract_metadata(url) + if not metadata: + return {'message': 'Failed to extract metadata'}, 400 + new_link = Link(url=url, name=metadata.get('title', ''), description=metadata.get('description', '')) + db.session.add(new_link) + db.session.commit() + readme_content = generate_readme() + update_github_readme(readme_content) + return {'message': 'URL submitted successfully'} + +def main(): + db.create_all() + app.run(debug=True) + +if __name__ == "__main__": + main()