Planet PyLadies Pune

December 10, 2017

Samridhi Agarwal

WebMaps with Python

After few months of busy schedule in college, Today I got the time to sit back and play with python applications. So I started learning WebMaps with python and folium.

As WebMaps the name only says that its the demonstration of Maps using browser. They can not be made using the default functions of Python because for the browser application we need CSS, HTML and JavaScript. So we need to convert the python code into the HTML code. Folium, a third party library does the same.

We need to pip install folium, after that we import it in the project. How folium works is – Everything spins around a map object, So we create a map object and store it in a variable.

import folium
map = folium.Map

Here folium.Map is the class that creates the object “map”. You can do dir (folium) to see different functions and you will find Map there. Then we can do help (folium.Map) to get the parameters and what we can give in that class.

Screenshot from 2017-12-10 22-29-19Screenshot from 2017-12-10 22-32-41

In the parameters we see the Location attribute to specify the coordinates on the world Map.Width- which means you can specify the width of map to be displayed on browser window, otherwise 100% by default means it uses full browser window to display.Tiles is background of map and so on.

So We can give the location attribute and see the location. In the location attribute the coordinates are given as [latitude, longitude].

import folium
map = folium.Map([-90 , 50])

Now we have a map object in python code but it is not converted to HTML. So we point the map object and use save method to save it in the html form, creating a new html file. Map will be created in HTML format, So html is containing all the elements that render on the browser.

import folium
map = folium.Map([-50 , 50])
map.save("Map1.html")

So I got a Map1.html file having the map of my latitude and longitude mentioned and as it is interactive mapping we can zoom in and out to see more details. Zoom parameter can also be added as (zoom_start = 6) and see changes with different zoom factors.

screenshot-from-2017-12-10-22-53-06.png


by samridhiagarwalblog at December 10, 2017 05:28 PM

November 28, 2017

Pooja Yadav

FAD i18n 2017

We had i18n FAD from 20-22nd Oct in Red Hat, Pune office. Developers and QE both participated in FAD(Fedora Activity Day). So we all were excited. All preparations were done, thanks to Parag. Sundeep, Pravin and other members for their efforts to make this happen.



Day 1:
We started at 9.30. There was a introductory session by Pravin and Jens, followed by some logistics information by Parag. After this we started with planned sessions as all of us were going to discuss on the topics which we have planned by giving a small presentation.
First was Akira Tagoh who shared information about fontconfig , guidelines for defaults fonts and the tasks planned for FAD. Then Peng Wu discussed about Pango. After this we had a small break.
Fujiwara, Peng, Mike, discussed about input method, ibus. I got a lot of input from this discussions as I was going to work on Input Method Automation. Then Mike and Rafal discussed about locales.
It was lunch time by this, so we had lunch in office.
After having lunch Sundeep, Parag, Sachin gave presentation and discussed about Transtats. Then Pravin discussed about Fonts. I gave a small presentation on Input method and tasks for Automation.
Then Satya and Bhushan discussed about the Fedora i18n QA Test cases. After this Vishal who was participating remotely in FAD gave presentation and share his idea web testing.
After a small break, everyone shares their plan for the projects on which they were going to work.


Day 2:
Second day we started at 9, as everything was set and planned. We started working on our projects. I and Ompragrash were working on the Input Method Automation. So first we planned to do automation for GNOME application as well as libreoffice. So first task was to open the application in specific locale. So I decided to do for gedit and Ompragash took libreoffice. We took Korean and Chinese input method. In the first half we were able to automate to open the application in the specific language.

Next task was to enable the input method for specific language which took a bit of research, as Fujiwara and Peng Wu were there, we discussed with them and finally got the solution how we can enable the input method.
So EOD we were able to input string in the application by enabling the input method for specific language.
Then it was the time for daily sharing, we all gave demos and shared what we have done or achieved so far. It was a fruitful day for all as everyone made success on their projects.
After this it was the party time, we went Amanora where we did bowling, everyone enjoyed alot. Then we had dinner at Barbeque Nation. It was a nice evening.

Day 3:
We started at 9:00 am in morning working on our pending tasks. We already had a session planned for Modularity, we had a good discussion about Modularity, got to know many new things. After Lunch we had Fedora 27 release party in RedHat office only. Many people join us for the party where had discussion about Fedora and modularity as this is the major change in Fedora. In evening we wrap with the demos and presentation of our project.

I found it very good as I got learn many new things and also got a chance to interact with people working on different technologies. After this FAD I know whom to contact if I have any issues related to i18n , this event was good to build connection. This will help us in future.







Looking forward for next year FAD.

by Pooja Yadav (noreply@blogger.com) at November 28, 2017 05:34 AM

November 23, 2017

Pooja Yadav

Science Hack Day-2017,Belgaum

Finally it was the time to go the most awaited event "Science Hack Day" to meet and hack with the passionate people. This time also the venue was "Sankalp Bhoomi"  a resort built totally from discarded materials and salvaged waste.

Day 0:
We started here from Pune early morning for Belgaum and reached there by Lunch time. After reaching we were happy to meet people there, everyone was busy preparing for SHD Day-1. Then we had lunch. After lunch we put our stuffs in room and were told to take some rest but who wants to take rest when so much of interesting things were  going around. So after keeping the luggage in the room, we joined other people in the discussions. It was good to meet people whom we met last year, also good to meet new people . After the discussions we decided to do kayaking as I enjoyed it a lot last time. Also this time we had cycles in  Sankalp Bhoomi just to take a ride around it, so all of us enjoyed that. Then in the evening there was a introductory session where all of us gathered to introduce ourself and know each others hack idea .  This session was very good as we came to know about different projects and hacks which we can join .


Day 1:
After having breakfast, we started with Inaugural Function. Then Mentors shared their hack ideas, so that people can join any team according to their interest. Also,we had an aero modelling session followed by the practical where we can see the aircraft fying. After this people moved to the hacker space. Groups were formed and people started working on their ideas. 3D pens were the point of attraction which were brought by Nisha and Siddhesh, also 3D printer setup was a major task on which lot of people were working. 
There was a soldering workshop which was conducted by Jithin in which school students were having two projects. I helped in that work shop by helping students with soldering and troubleshooting as in the end some of the circuits were not working . So I just helped them to fix it.
After this we had lunch, then I moved to the hacker space and tried something with 3D pen. I was quite interested about the dome project after listening about in morning  introduction so went there to see how actually people are trying to implement it. It was good to see that they was able to make a base for their dome, they all were working very hard as it was very difficult task as it include so many skills, as some people were drilling holes in bamboo, some were doing calculations, some were tying the bamboo and many more. So hats off to their team effort. 



In evening after tea break again hackers started with the hacks. Then we had lightening talks and dinner. The day didn't finished here, after dinner there were a lot of discussion around technologies and many other things. I went to bed as I was tired and feeling a bit sleepy but the discussions were still going on and in the morning I came to people went to sleep at 4.30 am. 

Day 2:
In the morning as I stepped outside I can't stop myself to take a round around Sankalp Bhumi as it was so refreshing. Then breakfast was served and after that people started with their hack ideas. As by lunch they have to finish with their hack. After lunch we all gather in the ground for SHD Group Photo, also we did rocket launch made by the students in their workshop. After that hacker moved to main hall to present that ideas, they grabbed a table and set up the project there. Then all people moved to them to see what they have done in the last to days, they explained their projects. After that there was voting to award the best hack.After voting was completed, everyone was waiting curiously for the result in the mean time Hitesh was there to address the crowd. Then the result came and the winning team was awarded. It was great to to see the Team making the Dome won as they had put a lot of hard work as working without caring about the hot weather and also the ground was slippery due to rain last night. Then students went to their home. Discussion continued with Dinner and after.....

Highlights:
Session on Aero Modelling: This session taught about the basics of aircrafts and we get to know the functions of aircrafts parts. Also it was fun watching that aircraft in action as it take off touching the sky and returing back to the ground.

3D Pen: 3D pen the point of attraction for whole from kids to adults. They tried with writing their name to making some 3D images. I also tried some stuffs and make a model for the Dome which people were making.


3D Printer: 3D printer, everyone was excited to see that working. So people were trying to assemble it. It was also interesting


Dome Home: I find it quite interesting as people were quite involved in it starting from drilling, nailing the nails, measuring and tying the bamboos, maintaining the symmetry. Also I loved the chandelier made by the girls as a decorative item for the Dome Home.


Ping-pong Ball:  This was a nice project the students, it was nice to see the ball dancing on the top of water.

Mixture prepared by Praveen Patil:  It was a great effort by Praveen to prepare that liquid mixture on which we can walk. So he made it possible walking on liquid without getting into it. Nice experiment by him.

Interaction with SHD-San Francisco: In SF Science Hack Day was going on in parallel, so it was nice to connect with hackers across the globe.

So, attending Science Hack Day was one of the best part of this year for me. Thanks to all the organizers, sponsors, mentors, volunteers and participants for making this event successful . 
Looking forward to attend SHD-2018.

Keep Hacking........

by Pooja Yadav (noreply@blogger.com) at November 23, 2017 11:57 AM

October 10, 2017

Pooja Yadav

Fedora Women Day-Pune Sept,2017

On Sept 28,2017 we celebrated Fedora Women Day in D.Y PATIL COLLEGE OF ENGINEERING, Pune. As decided we all(Amita, Satyajit, Madhuri and me) were in office at 8.30 to leave for the venue. Amita booked a cab and we headed towards the destination. When we reached the college we were welcomed by Suvarna mam. Lot of things were going on there as they were preparing for some event, some construction work was also going on. All this reminded me of my college days and my memories as a student refreshed after watching the college students busy in different tasks.
Then we had a short break as they have to shift the audience to another room due to more number of participants then expected. After the break we were ready to start the event. It was nice to see that a major part of audience were girls. Then they welcomed us with the sacred plant “Tulsi”, it was an honor to get that.
After that we started with Amita’s talk on the topic “ Women in Open Source”. She started with a motivational discussion about the facts and myths which people have about women and that boosted up the stamina of each and every girl sitting there.  Then she covered What is Fedora and how they can contribute to it. She also talked about Women in Open Source Award and shared stories of some great women. After her talk was over she asked students to come up to give their intro, tell us how they feel about it and in which part they think they can contribute according to their interest. As the students were shy, again she pushed them a bit and promised to give awesome Fedora Women Day stickers :) and Fedora Live CD’s which Praveen gave us, thanks to him for that. Then two girls came up and share their ideas. It was really a very motivating talk by Amita.
















Next was Satyajit who was going to show how we can install Fedora in our laptop without messing up with the current OS or our data. As we have a discussion before with the faculty there that some student lost their whole data while installing Fedora, so here he come as a savior for those student. He very clearly explained and showed how they can safely install Fedora from an iso image without harming their data. He helped student to get started with Fedora as most of them were new to Fedora.


After Satyajit it was my turn to explain how they can install various packages and get started after installation of Fedora. So I introduced them to DNF. I gave a brief history of yum, dnf and about transition from yum to dnf. After this I showed them how they can install, update, remove packages using DNF. I gave them basic information about different commands and how they can see help or man pages. I asked some questions in the end and gave stickers to the audience. It was really a great experience with college students.



Then Madhuri came up with her talk on “Fedora loves Python” . She explained about Fedora and Python. She told them how they can contribute to Fedora and showed them different options available where they can contribute according to their interest. It was very informative.

This event was very useful, as most of the student had this in mind that they can contribute only if they know coding. But this cleared all their doubts by giving them a detailed information about the different options available where can contribute according to their interest.


After these session we gave remaining CD’s and Stickers to the students and finished the event with a thank you note. Then after lunch we were back to our office.

It was a great experience and awesome event :-)

by Pooja Yadav (noreply@blogger.com) at October 10, 2017 10:22 AM

September 18, 2017

Rishika Goyal

Behave and Selenium installation steps.

Selenium is a simple API to write functional/acceptance tests using Selenium WebDriver. Through Selenium Python API we can access all functionalities of Selenium WebDriver.

Behave is a simple python module that allows us to write tests in simple natural language.The tests written using behave module are backed up by Python Code which generally uses functionality of selenium for testing the Web Application.

1)Ensure Python3 is installed because we will be using python3
in our example.

2)Setting up Virtual environment.

a) Install vitualenv

pip install virtualenv

b) Create a directory for the project

mkdir project_dir

c) Create a virtualenv inside the directory with python3 as the default interpreter.
cd project_dir

virtualenv -p /usr/bin/python3 my_project

d) Activate the virtual environment

source my_project/bin/activate

3)Installing Behave

Install the python module “behave” in the virtual environment “my_project”

$pip install behave

Check if behave installed properly or not by importing the module in the interpreter.

[rgoyal@localhost ~]$ python3
Python 3.5.3 (default, May 10 2017, 15:05:55)
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import behave
>>>

The interpreter mustn’t give prompt saying No module named behave

4) Downloading, installing and configuring selenium.
a) Install Selenium in the virtualenv my_project

$pip install selenium

b) Download geckodriver from Downloads section in the link given below.
Geckodriver is Firefox’s web driver that helps in automating . Make sure to download the one that corresponds to your system’s architecture.

Note: The linux 64 bit geckodriver is 3rd in the list

https://github.com/mozilla/geckodriver/releases

c) After downloading geckodriver, extract the tar ball

$tar -xvf <path of geckodriver>

c) Copy the geckodriver executable to /usr/bin

mv <path to geckodriver> /usr/bin

d) Verify that selenium is correctly installed by running this sample python code

in a file named example.py. [You can find this code and it’s explanation here: http://selenium-python.readthedocs.io/getting-started.html]

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get(“http://www.python.org&#8221;)
assert “Python” in driver.title
elem = driver.find_element_by_name(“q”)
elem.clear()
elem.send_keys(“pycon”)
elem.send_keys(Keys.RETURN)
assert “No results found.” not in driver.page_source
driver.close()

 

$python3 example.py

The firefox browser must open and take you to the python.org site.

With this you are all set to test your Web Applications.

Happy Coding!!


by PyRishika at September 18, 2017 07:04 AM

September 09, 2017

Samridhi Agarwal

Euler Problem no.30 with Python

This problem statement was quite interesting because that not only judged my coding skills but also my mathematical skills. So i tried to solve it in two different ways –

Problem Statement
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44

As 1 = 14 is not a sum it is not included.

The sum of these numbers is 1634 + 8208 + 9474 = 19316.

Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

Solution –

I first thought of getting the set of numbers (which meet the problem’s criteria) that are to be added, and then add them together to verify that the set is correct and complete.

Secondly, make a list of constraints which put restriction on the solution set. This problem excludes the value 1 from consideration. In fact, by intuitive extension, it is excluding all single digit values (numbers < 10) as they cannot form a sum of digits. This is a clue that our search range starts from at least 10.Now we have to think on the end range that’s the maximum limit till which our code should search. After just a moment of thought it becomes clear that the number of digits for the sum must have the same number of digits as a value.
Look at the table below to get the maximum limit.

Digits Maximum n Limit = 95 x n Comments
9 999,999,999 531,441 they need to have the same no. of digits
8 99,999,999 472,392 nope, still too many digits of n .
7 9,999,999 413,343 not quite there
6 999,999 354,294 a valid search limit

So we got the maximum limit as 354,294 . Now let’s write the code.

Python Code –

TotalSum = 0    
Value = []                             #values to be added

#Range we got and then comparing the values according to criteria
for i in range(10, 354294): 
    Sum = 0                       #This sum is for getting one single value 
    for x in str(i):
        Sum += int(x) ** 5        #checking for main condition with power 5 
    if Sum == i:                  #If the sum matches with the value 
        Value.append(i)           #The value we are in search for 

# We add those values stored in the list to get total Sum
for i in Value:
    TotalSum += i

print ("Values :" , Value)
print ("TotalSum :" , TotalSum)

Output ->

Values : [4150, 4151, 54748, 92727, 93084, 194979]
TotalSum : 443839

I also tried with other way by defining a function.

Python Code ->

def power_of_digits(n, exp = 5):
    Sum = 0
    while n > 0:
       Sum += (n % 10)**exp
       n //= 10
    return Sum

total = 0
for i in range(10, 10**6):
    if power_of_digits(i) == i:
        total += i
print(total)

Output ->

443839

Happy Coding! 🙂


by samridhiagarwalblog at September 09, 2017 02:55 PM

September 07, 2017

Samridhi Agarwal

Euler Problem no. 4 with Python

I Solved the 4th problem from the Euler’s problem set using python and found that it can be done in multiple ways. The problem is related to palindrome concept.

Problem Statement – 
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.

I first approached the problem statement by thinking that how many maximum digits will a number have so 2 three digits will have max 6 digits number when multiplied and that can be easily achieved by first multiplying the biggest numbers so I took a reverse loop. And then checked the condition of being a palindrome number and displayed the greatest one after comparison .

Python Code ->

palindrome = 0 
# 2 variables to find the biggest palindrome
for a in range(999, 100, -1):       #First factor

#second factor starts from a so that one multiplication does not repeat.  
    for b in range(a, 100, -1): 
        number = a * b  
        if number > palindrome: 

#To check if number is a palindrome. 
            x = str(a * b)   
            if x == x[::-1]:  
                palindrome = a * b  
print(palindrome) 

Output ->

906609 

Trying More Euler’s Problem and the same code with C++. 🙂


by samridhiagarwalblog at September 07, 2017 02:50 PM

Back to Coding Life!

After all this long time I returned back to my hostel (after a lot more traveling and sad days). Everything seems stable now and I wish this remains for a longer time. So today as I returned back there were many things and many tasks to be completed – the internship work (mainly), I missed the dgplug sessions 😦 (reading the logs), Assignments and College.

So Completed with few things now and enjoyed the whole day with my laptop (after 7 days long holiday). First I did the tasks of the internship work (still left with much more). Read the previous 4 logs which i missed (dgplug). There was a session in dgplug where warthog9 was there for the guest session. He was the one who gave us the battle bunnies in the PyCon Pune 2017 and i also wanted to ask him few things about the bunnies but hard luck missed the chance! But the session was great i read the logs and got to learn many things about hardware. 

I think I will take one more day to return to the normal schedule where i can write atleast two codes a day and learn things. Still I tried to complete most of the things (satisfied by myself 😛 ).


by samridhiagarwalblog at September 07, 2017 02:26 PM

August 25, 2017

Samridhi Agarwal

Euler Prolem no. 2

I solved the second question from the euler’s problem set with python first then i tried to do the same with c++ and I realized that it just does the same thing and same logic to be applied just increasing number of lines to code in C++.

Problem Statement – By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

So I will start with how I first thought of writing a precise and simple code. As the last digit in the Fibonacci series is the sum of all the prior numbers so if we minus all the odd values from last digit that is 4 million, we will get sum of all even numbers. But i went with searching for all the even numbers one by one till 4 million and adding them.

Python Code ->

sum = 0               # Assign variable sum as 0
a, b = 0, 1                # Taking a and b as values in Fibonacci series
while b < 4000000:         # Last value should be 4 million
    if b % 2 == 0:         # Checking if even
        sum += b           # Adding up all even values
    a, b = b, a + b        # swapping first value with second
print(sum)                 # print the sum 

Output ->

 4613732   

C++ Code  ->

#include 
using namespace std;
int main()
{
	int sum = 0;
	
	//3 variables to create the Fibonacci sequence from 0 to 4000000
	int a = 0;
	int b = 1;
	int c = 0;
	
	while (b <= 4000000)
	{
		c = a + b;
		if (b % 2 == 0)      //check for even number
			total += b;
		a = b;
		b = c;
	}
 
	cout << sum <<endl;
	return 0;
}

Output ->

 4613732  

Practicing more Euler’s problem.


by samridhiagarwalblog at August 25, 2017 05:33 AM

August 22, 2017

Samridhi Agarwal

Emacs Lisp

In yesterday’s dgplug session, we were taught the Emacs Lisp programming, something very new for me which I had never done before. I liked the way the code is written because of its simplicity and normal English language but the way in which parenthesis are put is little confusing. That can be actually done by practicing writing code in Emacs Lisp. I was given a link to a video in the session by the mentor which i found really helping. I summarized all the codes with comments we learned in the session. You can have a look for them here .

After the session we also got some work to do – We have to select a problem from the Project Euler  and implement the solution in Emacs Lisp. So I selected the very first problem that is –

Find the sum of all the multiples of 3 or 5 below 1000.

I first wrote the code in python –

sum = 0                           #assigned sum variable as 0
for i in range(0, 1000):          #used range function to iterate from 0,1000 in the for loop
if(i % 3 == 0) or (i % 5 == 0):   #checked the condition
sum += i                          #if true then add with sum 
print (sum)                       #print total sum

Output ->

 233168 

I tried to proceed in the same way for Emacs Lisp programming and i got the output in two ways once defining a function and one without function.

1) Defining the function sum

(defun sum (list)
  (apply '+ (mapcar
	     '(lambda (x) (if (or (eql (% x 3) 0) (eql (% x 5) 0))
			      x 0) )
	     list) ))
(sum (number-sequence 1 999) ) 

Output ->

 233168 (#o707320, #x38ed0, ? ) 

In the first line I defined the function sum with parameter list then I wrote a condition to check and add all the numbers satisfying the condition to give the total. To give the range I used the number-sequence function.

2) Without using function and using loop (do)

 (let ((sum 0))
  (cl-loop for x from 1 to 999
	   do (if (or (zerop(mod x 3 )) (zerop(mod x 5 )))
		  (setq sum (+ x sum))))
 sum)  

Output->

 233168 

Used the same logic but mentioned the range in the loop which is more problem statement oriented result.

I really liked the Euler’s problem statements will try to practice more from them each day.


by samridhiagarwalblog at August 22, 2017 07:42 PM