Hi! 😊

Internet Connection In Mauritius - Orange and Auto Post on Facebook

Internet Connection In Mauritius - Orange and Auto Post on Facebook

This post is more emphasize on the Script use to post on facebook rather than expressing my fury towards Mauritius Orange Connection.

For the past few weeks, the internet connection is being degraded to such level, that one gest fed up of browsing the net.

Being an inhabitant of a village, where Orange Fibre is not yet a reality, so right now all we can get from Orange is still the 1-4Mbps connection while paying for the same price in urban areas whose connections is from 10Mbps – 30 Mbps 😀

From the idea that a man try to tweet his internet speed to show his irritation, i try to create something similar that post on my wall on facebook.

Basically, its a cron which runs every 30 minutes which execute a python script but my result was so bad that  i had to stop the cron.

My result (The script was posting on my wall every 30minutes – which was annoying for my friends :D)


Here are my procedures used to make the script:

Install facebook library: (bash)
pip install facebook-sdk

Install speedtest for python: (bash)
pip install speedtest-cli

This is a great guide to create an app on facebook and get the access token: https://nodotcom.org/python-facebook-tutorial.html

Some tips which may help:
-After creating the app, to get the token, go to the page:

(developers.facebook.com -> Choose tab Tools & support -> Graph Api Explorer)

-On far right hand side, click on the Graph API Explorer and choose the application.
-On “Get Token” -> Choose Get User Access Token
-Click on Extension permission and click on “Publish Action” (base on your privacy choose who can view the post — Only Me, public or friends)
–You will get Access Token for a shorter Live
(if you want to execute the script for about 2-4hours else the access will be expired)

for a long live access token: (Around 1 month, then you need to regenerate it)
use this URL

he codes: (python_connection.py)
import time
import os
import facebook
import csv
import sys
import datetime

#Facebook Authentication
cfg = {
    "page_id"      : "###ID OF YOUR Username",  # E.g facebook.com/lol (so lol is your id)
    "access_token" : "YOUR ACCESS TOKEN"  

def get_api(cfg):
  graph = facebook.GraphAPI(cfg['access_token'])
  return graph
api = get_api(cfg)

a = os.popen("/usr/local/bin/speedtest-cli --simple ").read()

lines = a.split('n')

p = lines[0][6:14]
d = lines[1][10:14]
u = lines[2][8:11]

ts = time.time()
date =datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
#save the data to file for local network plotting
out_file = open('/var/www/default/data.csv', 'a')
writer = csv.writer(out_file)
#print d

if eval(d) < 1 :
        slow="#Orange -- Internet Connection is Slow : Getting Down:" + str(d) + "Mbits/s, UP: " + str(u) + "Mbits/s - Instead of 2mbpsDown/300kbpsUP!"
        status = api.put_wall_post(slow)
        print slow

  On crontab:   */30 * * * * sudo python python_connection.py   Have fun posting your internet connection of Facebook ^_^   This guide help me to get in touch with Facebook API and python scripting.  
More python scripts coming soon 😉 .. till then enjoy Pythoning 😀

Made with ♡ ♥💕❤ from Mauritius