It is Thursday again ! Every Thursday from 8am UMobile will give limited free voucher for its own subscribers. Example: Free Ice Cream, Movie Ticket, Candy, etc.
But I'm late raiser. So, the time when I awake, the deal is fully grabbed by others.
Instead of wake up that early, keep refreshing and compete with thousands of people. Why not I create a bot and do it for me? This idea came into my mind since long time ago, so this is the time to make this idea into reality.
Source code : https://github.com/jackgoh/umobile-thursday
Getting The API Requests
To get the requests that send from the app to the server, we need a web proxy act as a middleman, listen to all the requests. In this case, I used Fiddler web debugging proxy. But it only works on Windows tho. If you are OSX user, use Charles.
After setting up the proxy on my phone and launch the app. We can see few request are sending to mobileapps.u.com.my. Next is look for what request is useful for making the bot. In the app, navigate to rewards screen from the side menu.
Now, we got request link that retrieve all the voucher.
Next, is to get the assign voucher request. On the app, simply redeem a free voucher.
Wola, we got the request link that assign the voucher to my account.
List all voucher API
note: msisdn is your phone number, above is just an example
Assign voucher API
note: campaign_id is the campaign id from the promo voucher, above is just an example
Script above required to re-run every time before the campaign started. Here come version 2, where the script will run automatically every Thursday before campaign is started.
After exploring how to run Python script at specific time. I found APScheduler, a lightweight, in-process task scheduler.
Here is an example from the APScheduler Documentation of running jobs every Monday to Friday at 5pm:
from apscheduler.schedulers.blocking import BlockingScheduler sched = BlockingScheduler() @sched.scheduled_job('cron', day_of_week='mon-fri', hour=17) def scheduled_job(): print('This job is run every weekday at 5pm.') sched.start()
Now, I just change dayofweek to 'thu' and hour to 8. Then, paste my V1 script into scheduled job and done!
Not Yet! It will still require the PC to run 24/7 without any power outage.
Solution : Heroku
A cloud service what let you yo deploy your application and for free ! (limited)
- Install Heroku CLI
Create a file named "Procfile" and paste the content below
clock: python clock.py
Deploy to heroku
git push heroku master
Scale up the clock process
heroku ps:scale clock=1
Wola, server and script is up and running.
Then on every Thursday...