Working with new things… :)

After having many good sessions in free open source software workshop………We successfully wrapped it up and its time for workout on some interesting and challenging tasks for beginners to enter the club…….

Tasks were given in 3 categories viz Easy ,Medium,Hard ….out of which we can do as many as possible……moving into my works …

Level : Easy

1.Rock..Paper..Scissors..:

As many of us play this game with our friends for time pass….our task is to play this game with com …here’s how I made it

step 1: I start game by taking the winning score at first as input…hence who ever reaches the score first will be the winner ….

step 2: Next i will initiate two scores each for player and computer ….which are equal to zero before starting the game.

step 3: Next i will run a while loop to start the game and end it when score of either player and computer reaches to scoring point…..In while loop ….at each iteration player inputs his choice and then computer takes any one of rock,paper and scissors randomly….to execute this I imported random module…

step 4: Based on both outputs score changes at each iteration and when when anyone reaches the scoring point…the while loop ends and winner will be declared…here’s the link to checkout my work….

after playing a game……

            link : https://github.com/mustaqmustu/Tasks-foss/blob/master/rockpaperscissors.py

 

Screenshot from 2018-10-26 00-50-20

2.Telegram Bot:

Here I made a telegram bot by using telegram API which gives you latest flash news happening in India… for this I took skeletal code from the blog “https://www.codementor.io/garethdwyer/building-a-telegram-bot-using-python-part-1-goi5fncay” moving into my work…..

step 1: first of all we need to create our telegram account and from it we should get out bot token from Botfather….then we must be able to access our bot’s browser page i.e..”https://api.telegram.org/bot<yourtoken>/getme”……  that’s the page where you would be able to see your bot details and then if you send a message to your bot from your telegram account you must be able to see that details of message in the page “https://api.telegram.org/bot<your token>/getUpdate” page…and our code will be based on these pages ….

step 2:In our code we will first download the content in our telegram bot’s url by requests module and from then we will extract json data from our bot’s page and similarly get the details of message send to our bot from url “https://api.telegram.org/bot<your token>/getUpdate” and get out chat Id and “text” (text is nothing but the message that we send to our bot)

step 3: In this step we will send the desired reply to the message we received.As we get a list of messages sent to our bot….we will design our code as only to respond for the last received message by using offset concept and we will reply to the highest chat Id we got message from…

step 4: Next we will scrap the required data from a website.As I mentioned above about latest news…I am scrapping data from “Indiatoday” website as it allows large number of url requests…..For data scraping I used beautiful soup module.

step 5:Now we have to send this data as a reply….we can do this by updating  our url by adding text and chat ID content to the url.we import time module and make it to run and check for new messages for each 0.5 seconds.For all the steps mentioned above I have used functions which you can easily understand from skeletal code..

my news bot :

Screenshot from 2018-10-26 01-08-20

      link: https://github.com/mustaqmustu/Tasks-foss/blob/master/echobot.py

Level: hard

1.Twitter API to send status update from CLI:

To complete this task we require four tokens of our Twitter API  which gives access to our API from our code…..We can get this by creating a twitter app from developer of API twitter for which you have to apply for permission which takes sometime to be granted..After getting token we can proceed to our code…..

step 1:First of all we will import a module named “tweepy”  which is a library of twitter for python to handle different properties of twitter.

step 2: Next I stored all my tokens viz consumer key,consumer token,access token and access secret in four variables.

step 3:The next step is creating an OAuthHandler instance. Into this we pass our consumer token and secret  to authenticate ourself. And similarly our acess tokens.we then authenticate by giving command “api=tweepy.API(auth)”

step 4:Next we update our status by just giving a simple command “api.update_status”.That’s it , we have successfully updated our tweet…

updating tweet:

Screenshot from 2018-10-26 01-35-52

meanwhile in twitter:

Screenshot from 2018-10-26 01-39-57

       link :https://github.com/mustaqmustu/tasks-foss/blob/master/tweet.py

2.Sending gmail from CLI:

Instead of using GMAIL API …I have used a simple module viz “smtplib” ….a python library to send emails to different websites based on portals.

step 1: First of all I have imported smtplib which is crucial one…..

step 2:Next I will establish a connection by command “smtplib.SMTP(smtp.gmail.com,587)”,where 587 is the port of gmail.

step 3:Next ill input my gmail id and password and store it….as password is confidenital,I use getpass method to made it invisible while entering password.

step 4:next ill take to address and description and store it in variables.By using sendmail command..Ill send an email to the respective account..

sending an email:

Screenshot from 2018-10-26 01-14-15

link : https://github.com/mustaqmustu/tasks-foss/blob/master/mail.py

That’s the end of the tasks done by me.. 🙂  Hope these helps me pulling out further… 🙂

 

 

 

Advertisements

start@ amrita university

Hii, this is Mustaq Ahammad. I’m from Anantapur, Andhra pradesh.I joined in Amrita university, Amritapuri campus this year.I’m going to share my experiences at amritapuri campus.First when i came to the campus , i was very much scared about things like ragging , academics and new people.

It began with induction programme. It was a little bit boring but it gave me much knowledge about campus life and academics.Actually I enjoyed the tours.We went to ashram tour, ayurvedic hospital , waste management tour etc.. I enjoyed with my friends at sea shore . Rain irritates me much here.

During induction programme , we had a session with our seniors which cleared my doubts about ragging here. There is no ragging here. This reliefed me much. After ten days of induction programme , our classes started. At first they went slow. But after 3 days assignments hit us hard.

We had many sessions about programming , coding etc…about which I don’t know anything. I was very much tensed by listening those things. But our seniors came to help us. They said that they too don’t know anything at first but we must take initiative in order to excel in them.

There are many clubs in amritapuri campus like bi0s , foss . code@amrita etc.. Foss is top notch in them according to me .But its very hard to get in there. As we are fortunate , our seniors started a workshop to make us excelled in basis which helps us much in future to join the club. Workshop is for 6 weeks. in first week , they taught us about how to google properly , basics of terminal line commands , how to email effectively, IRC and blogging. Today is the last day of 1st week workshop.