Skip to content

Fixes to username status processing#7

Merged
MatteoCampinoti94 merged 1 commit intoFurryCoders:mainfrom
Xraydylan:patch-1
Nov 2, 2022
Merged

Fixes to username status processing#7
MatteoCampinoti94 merged 1 commit intoFurryCoders:mainfrom
Xraydylan:patch-1

Conversation

@Xraydylan
Copy link
Contributor

Changed:
parse_watchlist Uses space separating user status and user name to get user.
parse_user_page Users URL in meta tag to get user name. However, the user name from the meta tag url is lower case. Thus a lenght comparison is used to determine if status symbol is present.

Added:
parese_username_from_url Takes url and returns username under the assumption that the last part of the url is the username

What is still needed:
Adjustment of parse_user_tag function is still needed.

Changed:
 `parse_watchlist`  Uses space separating user status and user name to get user.
`parse_user_page` Users URL in meta tag to get user name. However, the user name from the meta tag url is lower case. Thus a lenght comparison is used to determine if status symbol is present.

Added: 
`parese_username_from_url` Takes url and returns username under the assumption that the last part of the url is the username


What is still needed:
Adjustment of `parse_user_tag` function is still needed.
@Xraydylan
Copy link
Contributor Author

I hope this is good?

@MatteoCampinoti94 MatteoCampinoti94 added the enhancement New feature or request label Nov 2, 2022
@MatteoCampinoti94 MatteoCampinoti94 merged commit bb6d849 into FurryCoders:main Nov 2, 2022
@MatteoCampinoti94
Copy link
Collaborator

I actually didn't mean too merge it yet, damn GitHub interface x3

It fails static type tests (because of missing type annotations), but the unit tests succeeded :)

I'll add the types and do some more thorough testing for edge cases, but it looks good!

@Xraydylan
Copy link
Contributor Author

Well, so far it seems to run very smoothly.
And I can say with quite confidence there hasn't been an error since.

@MatteoCampinoti94
Copy link
Collaborator

MatteoCampinoti94 commented Nov 2, 2022

I changed the watchlist parser to check the actual link, it contains the username without the status. It then removes the links and then just uses the remaining text stripping it of whitespaces.

I really like using the meta tag for the username, but unfortunately FA removes some underscore characters from URLs, so for example a user called "user_name" would have a url of "username", thus failing the equal length check :(

Not really sure why they specifically remove underscores, though I suspect it has to do with SQL queries (SQL like uses _ as regex's .).

@MatteoCampinoti94
Copy link
Collaborator

Changed it to this:

status: str = ""
name: str = tag_status.text.strip()
if username_url(name) != username_url(parse_username_from_url(tag_meta_url["content"])):
    status, name = name[0], name[1:]

username_url is the function I have been using to create the URLs for parsing, so it can be used to safely compare the two usernames.

I'm currently trying to come up with test cases to make sure it will actually work. I usually don't do these kind of comparisons because they evaluate to true in some weird cases.

@MatteoCampinoti94
Copy link
Collaborator

It's all integrated now, thank you for sharing your code!

@MatteoCampinoti94
Copy link
Collaborator

I'll just wait bit before publishing a new release though, wouldn't want to forget something, again x3

@Xraydylan
Copy link
Contributor Author

Oh!
Thanks for pointing that out.

Frankly, I haven't noticed that the URLs behaved like this. Of course the length check will fail that way.

Thankfully, the way it the check worked only allows 1 case, were it will give a faulty result.
Namely if an admin has a "_" in his name.
In all other cases the name generated from the URL will always be shorter than the username with status symbol, thus triggering the right case regardless.

Lucky me and my still running code...

@MatteoCampinoti94
Copy link
Collaborator

I found the edge case. There is a bug in FA's template that does not add the og:url meta to /journals/<user> pages 🤦‍♂️

@MatteoCampinoti94
Copy link
Collaborator

I've restored the admin image check for folders, it's still there for user pages. Sorry it didn't work :(

@Xraydylan
Copy link
Contributor Author

Xraydylan commented Nov 2, 2022

I mean...
You don't have to apologize to me.

I already knew that it wasn't in the template for journals/<user>.

This is why I didn't implement it and said it still needed to be done (some way).

Nonetheless, one could extract the username from one of the other paths of one of the tags on the journals site still 🤔
If that is still needed or just use the admin check.

@MatteoCampinoti94
Copy link
Collaborator

Still, it was a really good method and I hoped to use it for all pages.

Alas the journals page is missing almost all og meta tags :(

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Fur Affinity | For all things fluff, scaled, and feathered!">
<meta name="keywords" content="fur furry furries fursuit fursuits cosplay brony bronies zootopia scalies kemono anthro anthropormophic art online gallery portfolio">
<meta name="distribution" content="global">
<meta name="copyright" content="Frost Dragon Art LLC">
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=EDGE">
<meta property="og:image" content="https://www.furaffinity.net/themes/beta/img/banners/fa_logo.png?v2">
<meta name="twitter:image" content="https://www.furaffinity.net/themes/beta/img/banners/fa_logo.png?v2">

It could be changed to find the link to the journals page itself, using div.usernav a.current should do the trick. But at that point it is easier to just check for the admin badge, avoids having to parse the parent HTML of the user tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants