title: desktop python script retrieve sms messages sent to android device
body: <p>I have a web scraper written in python/selenium that runs daily on a home server. One of the sites I'm scraping have recently introduced 2FA which overall I'm in favour of however the downside is that it has broken my automation as now a one-time-passcode is sent via SMS to my mobile number - which needs to be typed in before the script can continue. To get my script fully automated again I need a means for my desktop python script to poll my android device for its SMS messages.</p>
  
  <p>I looked at Twilio however the docs suggest it doesn't fit my use case as; </p>
  
  <blockquote>
    <p>Hosted SMS provides a method for customers to use Twilio ... to send and receive messages on voice-enabled numbers they already own ... Hosted SMS supports USA &amp; Canada in Beta. Mobile numbers are not supported.</p>
  </blockquote>
  
  <p>Google have the <code>SMS Retriever API</code> which also doesn't fit my purpose as it requires a custom hash code in the message body and the <code>SMS User Consent API</code> requires the user to tap the screen to approve each request (which of course isn't fully automated). </p>
  
  <p>The quickest haphazard method I can think of to get these OTPs to my python script would be to write a simple discrete mobile app with permission to access SMS and create the following workflow:</p>
  
  <ul>
  <li>have the desktop python script pause when it reaches a 2FA screen and listen on a specified UDP/TCP port</li>
  <li>have the mobile app simply looking for messages from a target number (or with a target phrase)</li>
  <li>when such a message arrives the app would encrypt the message text, and</li>
  <li>send it via UDP/TCP to the aforementioned port on my home server </li>
  <li>let the script decrypt and parse for the OTP (or timeout after x minutes)</li>
  </ul>
  
  <p>Ideally the only thing that would hinder the workflow is if my phone happened to be off at the time that the script runs.</p>
  
  <p>... rather than cludging this together I am wondering if anyone can recommend a better means (or API) of achieving this?</p>