Skip to content

add prompt functionality (in progress) #62

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

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

rabpitpie
Copy link

@rabpitpie rabpitpie commented Mar 7, 2024

This adds (incomplete) functionality to scrape data from /collections/{collection name}/prompts/{prompt id}
eg. /collections/test_prompt_meme_2024/prompts/3566161
I mostly copied the existing code, I hope it worked out!

Includes:

  • prompt posted date
  • prompt id
  • summary as HTML
  • collection name (url name)
  • collection display title (title displayed to visitors)
  • ratings
  • prompt author
  • fandoms
  • warnings, characters, relationships and additional tags
  • claims(1)
  • categories

Does not (yet) include:

  • is prompt filled?
  • get prompt title (more difficult that I expected!)
  • get prompt fills. I created an interface for this but did not get to start working on it.

Issues

  • (1) We've had discussion about revising the interface prompt > claims.
  • I think this page cannot be accessed in closed prompt memes when the visitor is not part of the prompt meme
  • I don't know how to access this page for exchanges, and can't be certain it exists for that challenge type. (for prompt memes, the prompt id can be found on the /collections/{collection name}/requests page, on the prompt's claim button's form action url.)

rabpitpie added 30 commits March 2, 2024 16:05
…wn prompt claimers. Squished bugs this created
Copy link
Member

@essential-randomness essential-randomness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the excellent work, please let me know if any of the comments are unclear.

@@ -34,6 +34,7 @@
"scripts": {
"build": "rm -rf dist/ && tsup src/index.ts src/urls.ts --format esm,cjs --dts",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --no-cache .test.ts$ --verbose=true",
"test-prompts": "NODE_OPTIONS=--experimental-vm-modules jest --no-cache prompts.test.ts$ --verbose=true",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change, we'll add documentation on how to do it without needing to add a new script.

relationships: getPromptRelationships(promptPage),
additional: getPromptAdditionalTags(promptPage)
},
//TODO:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fill or delete this TODO



export const getPromptDetailsFromUrl = ({
// defining the input structure, eg.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might work better as a single function-level comment. You could write it as:

/**
 * Extracts promptId and collectionName from the URL of a collection.
 * 
 * For example, given the url "https://archiveofourown.org/collections/mo_dao_zu_shi_kink_meme_2020/prompts/2644428"
 * this function will return:
 *   - promptId: 2644428
 *   - collectionName: mo_dao_zu_shi_kink_meme_2020
 **/
export const getPromptDetailsFromUrl = ({ url, 
}: {
  url: string;
}): {
  promptId: string;
  collectionName: string
} => {

promptId: string;
collectionName: string
} => {
const promptUrlMatch = url.match(/prompts\/(\d+)/);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to merge these in a single regex test, something like:

const collectionUrlMatch = url.match(/collections\/(\w+)/prompts\/(\d+)/);
if (!collectionUrlMatch) {
  throw new Error("Invalid prompt URL");
}
 
return {
  promptId: collectionUrlMatch[2],
  collectionName: collectionUrlMatch[1]
};

Double-check that I'm extracting the groups correctly, cause I always forget the syntax.

promptId: string,
collectionName:string
})=>{
let workUrl = `https://archiveofourown.org`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do this with a single return statement like

return `https://archiveofourown.org/collections/${collectionName}/prompts/${promptId}`


describe("Fetches prompt information", () => {

test("Fetches prompt published date", async () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"published date and summary"

});
});

test("Fetches Prompt Categores (single)", async () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/categores/categories

});


//WIP PROMPTS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comment


});


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: i think this file is getting long so it might be worth considering splitting it in multiple files

collectionName: "mo_dao_zu_shi_kink_meme_2020",
id: "1909048",
filled: true,
// fills: [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are commented out for a reason, write a comment about why, if not either uncomment or delete.

@@ -34,6 +34,7 @@
"scripts": {
"build": "rm -rf dist/ && tsup src/index.ts src/urls.ts --format esm,cjs --dts",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --no-cache .test.ts$ --verbose=true",
"test-prompts": "NODE_OPTIONS=--experimental-vm-modules jest --no-cache prompts.test.ts$ --verbose=true",
Copy link
Member

@essential-randomness essential-randomness Mar 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the way to do this should be:

npm run test -- prompts.test.ts$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants