Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
debdutgoswami committed Jan 2, 2020
1 parent 764a2d5 commit 80af4b4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 40 deletions.
27 changes: 10 additions & 17 deletions ProfileImage.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import urllib.error, urllib.parse, urllib.request
import requests
import urllib.parse
from PIL import Image
from io import BytesIO
from bs4 import BeautifulSoup
import re, sys

def image_url(url, ctx):
def image(url, username):
session = requests.session()
#header parameter is used to resolve the bad gateway 502 error
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
#html = session.get(url, headers={'User-Agent': 'Mozilla/5.0'}).text

#opening the URL and parsing it into BeautifulSoup
try:
html = urllib.request.urlopen(req, context=ctx).read()
html = session.get(url, headers={'User-Agent': 'Mozilla/5.0'}).text
except:
print("Page not found or No internet connection")
sys.exit()
Expand All @@ -19,19 +21,10 @@ def image_url(url, ctx):
tags = soup.find_all('body')

#using regualr expression to extract the image URL
profile_pic_url_hd = re.findall("profile_pic_url_hd\":\"([\S]+?)\"",str(tags[0]))[0]
profile_pic_url_hd = re.findall(r"profile_pic_url_hd\":\"([\S]+?)\"",str(tags[0]))[0].replace(r'\u0026', '&')

return profile_pic_url_hd

def image_show(profile_pic_url_hd, username):
"""opening the image from the the URL,
saving the opened image
Arguments:
profile_pic_url_hd {string} -- profile pic url
"""

response = urllib.request.urlopen(profile_pic_url_hd).read()
response = session.get(profile_pic_url_hd, headers={'User-Agent': 'Mozilla/5.0'}).content
img = Image.open(BytesIO(response))
img.show()
img.save("{}.png".format(username))
img.save("{}.png".format(username))

14 changes: 0 additions & 14 deletions certificate.py

This file was deleted.

Binary file removed main.exe
Binary file not shown.
8 changes: 3 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#custom imports
import username, certificate, re
import username, re
import ProfileImage as pi

url = username.user_url()
usname = usname = re.findall("https:\/\/www.instagram.com\/([\S]+?)\/", url)[0]
ctx = certificate.context_ssl() #this step is not mandatory but advicable
usname = re.findall(r"https:\/\/www.instagram.com\/([\S]+?)\/", url)[0]

profile_pic_url_hd = pi.image_url(url, ctx)
pi.image_show(profile_pic_url_hd,usname) #opens the image in a new window and also saves the image in the working directory
pi.image(url, usname)
5 changes: 1 addition & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@

#### ESSENTIAL LIBRARIES FOR MAIN FUNCTIONALITY ####

urllib
beautifulsoup4
ssl
re
bs4
Pillow

0 comments on commit 80af4b4

Please sign in to comment.