-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
Ideas / Refactoring
I stumbled across multiple really good ideas for big refactoring.
Before really doing this, we should have a place to discuss the road to 5.0.
You wanna discuss about an idea written here ? Quote the part and answer with your own thoughts ! Quoting is important since this post might change really often, so everybody still knows what the state on your comment was :)
API ideas by @ishandutta2007
I have been meaning to stir this discussion , maybe this is the right thread, we have way too many APIs to do the same or similar things. This kind of design is making it a hell to maintain the code.
How I see is there should be one and only one api which does this three steps:
Choose target user(by tag, or by location, or by hashtag or from Followers/Following of a user, from a specific list).
Choose the desired item of that user(post or profile or comment)
Interact with that item(follow or like or comment).
If we see these three steps separaly we may enhance either of one of these three steps iteratively than trying to create new workflows which are essentially new combination of a usecase of these three steps.
You can expose these three APIs separately or wrap with one. To start we can create a universal wrapper and refactor incrementally later as and when we get opportunity.
HTTP API by @converge
would be awesome if you could wrap up your thoughts here
Extension Management by @breuerfelix
InstaPy package gets an additional folder named extensions. Every Extension (like Clarifai in this example) gets its own folder in this directory.
Extensions will be programmed only in their folder. This will keep the main codebase clean.
Interaction of Extensions with the core:
We create on Singleton called Event for example. Lets assume Clarifai want to prevent the core loop from liking / commenting some pictures.
There will be a function called event.before_interaction(image). The core function will call this function before liking / commenting a picture and if it returns true it will like it and it will skip it if it returns false.
The clarifai extension can then add its validator function for this event. event.add_listener('before_interaction', self.validate_picture). self.validate_picture will be a function which checks wether the image is inappropriate or not. (returning true or false).
event.before_interaction(image) is now calling ALL functions added as a listener to its own event and if any of those is returning false, it will return false. Only if all callback functions are returning true, the image will be liked.
The users can now just import their clarifai extensions in the main.py from instapy.extensions import clarifai and add these to the main instapy object instapy.add_extension(clarifai).
This function will then add all the Listeners to the event object.
That way the core package is able to interact with any amount of extensions without knowing them.
The event singleton may grow in the future and will be the only gate between extensions and the core.
Managing XPaths by @converge and @analyticsdept
Given the recent issue with XPaths, it would absolutely make sense to maintain them in a constants file separate to the functions so they can be updated in a single place hopefully minimising some risk to the code.
Idea: Make a new git repository which contains only the current XPaths. Use jsdelivr to read in the current xpaths from repos master branch on each startup.
this file may be edited by any collaborator ! add your ideas and thoughts.
not a collaborator ? answer to this issue and I will add your ideas into this post !