Skip to content

Instantly share code, notes, and snippets.

@rounakdatta
Last active June 5, 2019 06:33
Show Gist options
  • Save rounakdatta/1170626cdd25cae401d053e404024d8c to your computer and use it in GitHub Desktop.
Save rounakdatta/1170626cdd25cae401d053e404024d8c to your computer and use it in GitHub Desktop.
Gather random image files and aggregate image files from two directories
import requests
import random
import os
def randomImageGenerator(width, height, counter):
myRandomNumber = int((random.random()*10000) // 10)
print("https://picsum.photos/id/{}/{}/{}".format(myRandomNumber, width, height))
rawImageRawOriginal = requests.get("https://picsum.photos/id/{}/{}/{}".format(myRandomNumber, width, height))
rawImageRawSmaller = requests.get("https://picsum.photos/id/{}/{}/{}".format(myRandomNumber, width // 10, height // 10))
f1 = open("./dir1/{}.jpg".format(counter), "wb")
f1.write(rawImageRawOriginal.content)
f1.close()
f2 = open("./dir2/{}.jpg".format(counter), "wb")
f2.write(rawImageRawSmaller.content)
f2.close()
def generateTheFiles(count):
os.makedirs("dir1")
os.makedirs("dir2")
for i in range(1, count + 1):
randomImageGenerator(300, 200, i)
def takeOutSameFiles(totalNumberOfFiles):
allFiles1 = os.listdir("./dir1")
allFiles2 = os.listdir("./dir2")
if set(allFiles1) != set(allFiles2):
print("dir1 != dir2")
return
for i in allFiles1:
f1 = open("./dir1/{}".format(i), "rb")
f2 = open("./dir2/{}".format(i), "rb")
content1 = f1.read()
content2 = f2.read()
if content2 in content1:
print("yay")
else:
print("nay")
generateTheFiles(20)
takeOutSameFiles(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment