This uses selenium and a few other standards, here’s all them parts
A few classes to hold our parameters. The primary class here is TwitterLocator. To manipulate the web zone you need to know what to click on, what to scroll to, heck even what to type in. We use selenium’s By module and make tuples for each as class attributes. Some of these were pretty heinous to find after the homepage update, so they’ll probably change next week and ymmv.
It starts innocently enough, loading a basic Chrome webdriver and loading the homepage. You’ll have to add your chromedriver to your path, eg. export PATH=$PATH:/path/to/chromedriver/folder. Uncomment the ‘–headless’ line if you don’t want it popping up on you.
The guts of the class uses the TwitterLocator class to navigate the site by overloading the __getattr__. We use a few WebDriverWaits to make sure the thing we’re looking for is on the page, and then find_element
We’ll chain together two methods and I guess quit too.
So when we do things like .login() we just chain together a bunch of attribute calls - calling self.login_btn calls self.__getattr__(self, 'login_btn') - and selenium commands. We get pretty sleepy through all these methods because this bot doesn’t care about FAST POSTS and has bad internet.
Once we’re logged in, go ahead and tweet the poll already. More of the same song and dance.