Beispiel #1
0
    async def ao3(self, ctx: commands.Context, msg: str):
        """
        Attach a preview of an Ao3 Work
        """

        try:
            wid = int(msg)
        except ValueError:
            mtch = re.match(
                "^https?://(?:www.)?archiveofourown.org/works/(\d*).*$", msg)
            if mtch is None:
                await ctx.send("Error: Please provide either a workID or a URL"
                               )
                return
            wid = int(mtch.group(1))
        async with ctx.typing():
            api = ao3.AO3()
            try:
                work = api.work(id=wid)
            except Exception as ex:
                await ctx.send("Error: Can't find a work with that ID/URL")
                await ctx.bot.pm_owner(
                    content="".join(traceback.format_exception(None, ex, None))
                )
                return
            disp = self.format_ao3(work)
            await ctx.send(embed=disp)
Beispiel #2
0
def main():
    api = ao3.AO3()

    tag_name = "Samantha \"Sam\" Carter/Jack O'Neill"

    converted_tag = urllib.parse.quote(tag_name).replace('/', '*s*')
    pages = api.handler.get_pages('', 'tags', tag=converted_tag)
Beispiel #3
0
    async def ao3(self, ctx: commands.Context, msg: str):
        """
        Attach a preview of an Ao3 Work
        """

        try:
            wid = int(msg)
        except ValueError:
            mtch = re.match("^https?://(?:www.)?archiveofourown.org/works/(\d*).*$", msg)
            if mtch is None:
                await ctx.send("Error: Please provide either a workID or a URL")
                return
            wid = int(mtch.group(1))
        async with ctx.typing():
            api = ao3.AO3()
            api.session.headers.update({'User-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15"})
            try:
                work = api.work(id=wid)
            except Exception as ex:
                await ctx.send("Error: Can't find a work with that ID/URL")
                print("".join(traceback.format_exception(None, ex, None)))
                return
            try:
                disp = self.format_ao3(work)
            except Exception as ex:
                await ctx.send("Sorry, something went wrong parsing that fic.")
                print("".join(traceback.format_exception(None, ex, None)))
                print(work._html)
                return
            await ctx.send(embed=disp)
Beispiel #4
0
import os
import sys
import random
import urllib.parse

from bs4 import BeautifulSoup

sys.path.insert(0, os.path.abspath('..'))

import ao3
from ao3.works import Work, iterate_pages

api = ao3.AO3()

# load HTML as soups
soups = []
for n in range(1, 200):
    with open("html_save/tags_html_{}.txt".format(n), 'r') as f:
        html = f.read()
        soups.append(BeautifulSoup(html, 'html.parser'))
print("Loaded soups. Getting works.")

all_works_html = iterate_pages(soups, 'work', save_HTML=True)

all_works = []
for id, work in all_works_html.items():
    work_item = Work(id, api.handler, load=False, soup=work)
    all_works.append(work_item)

api.to_json(all_works, 'first_200_works.txt')