<jupyter_start><jupyter_text><jupyter_code>import os
import io
import cv2
import matplotlib.pyplot as plt
import pandas as pd
import requests 
import shutil
from google.colab import drive
drive.mount('/content/drive')

target_folder = './drive/My Drive/strava_images'
if not os.path.exists(target_folder):
  os.makedirs(target_folder)
  
## Set up the cookies, image URL and filename
cookies = {'_dc_gtm_UA-6309847-24':	"1",
           '_ga':	"GA1.2.1768783673.1601295337",
           '_gat_UA-6309847-24':	"1",
           '_gid':	"GA1.2.1418838620.1603550866",
           '_strava4_session'	:"m1gr2lrb98pqg4ru2hp84um9l75u6os",
           'ajs_anonymous_id'	:"\"e662f558-5aff-4c0b-9d7a-411577bdb60b\"",
           'ajs_user_id':	"33570430",
           'CloudFront-Key-Pair-Id':	"<KEY>",
           'CloudFront-Policy':	"<KEY>
           'CloudFront-Signature'	:"<KEY>
           'sp'	:"13645f10-5d73-499a-bd1c-202ec4c6bd9a"
}

def scrapimg(image_url, filename):
  # Open the url image, set stream to True, this will return the stream content.
  r = requests.get(image_url, stream = True, cookies=cookies)
  print(r)
  # Check if the image was retrieved successfully
  if r.status_code == 200:
      # Set decode_content value to True, otherwise the downloaded image file's size will be zero.
      r.raw.decode_content = True
      
      # Open a local file with wb ( write binary ) permission.
      with open(filename,'wb') as f:
          shutil.copyfileobj(r.raw, f)
          
      print('Image sucessfully Downloaded: ',filename)
  else:
      print('Image Couldn\'t be retreived')
first = ['11136.png', [26.74678, 64.18262], [26.75905, 64.18262], [26.75905, 64.17050], [26.74678, 64.17050]]
delta = 0.012227
m = [18572,11136]
def createdata(file, n):
  i = [n[0]-m[0], n[1]-m[1]]
  second = [file, [first[1][0]+i[0]*delta, first[1][1]+i[1]*delta], [first[2][0]+i[0]*delta, first[2][1]+i[1]*delta], [first[3][0]+i[0]*delta, first[3][1]+i[1]*delta], [first[4][0]+i[0]*delta, first[4][0]+i[1]*delta]]
  return second
df = pd.DataFrame(columns=['file', 'A', 'B', 'C', 'D'])
arr = [[18572,11136]]
for a in range(10):
  newelem1 = [arr[0][0]+a, arr[0][1]]
  newelem2 = [arr[0][0], arr[0][1]+a]
  arr.append(newelem1)
  arr.append(newelem2)
for i in arr:
  filename = str(i[0])+'-'+str(i[1])+".png"
  image_url = "https://heatmap-external-a.strava.com/tiles-auth/all/hot/15/"+str(i[0])+'/'+str(i[1])+".png?v=19"
  data = createdata(filename, i) 
  df.loc[filename] = data
  scrapimg(image_url, filename)
df
im = cv2.imread(filename)
im_resized = cv2.resize(im, (224, 224), interpolation=cv2.INTER_LINEAR)

plt.imshow(cv2.cvtColor(im_resized, cv2.COLOR_BGR2RGB))
plt.show()
fig = plt.figure()
ax2 = fig.add_subplot(1,3,1)
ax2.imshow(mpimg.imread('18574-11136.png'), extent=(df.loc['18574-11136.png']['A'][0], df.loc['18574-11136.png']['C'][0], df.loc['18574-11136.png']['A'][1], df.loc['18574-11136.png']['C'][1],), zorder=1)
ax1 = fig.add_subplot(1,3,2)
ax1.imshow(mpimg.imread('18575-11136.png'), extent=(df.loc['18575-11136.png']['A'][0], df.loc['18575-11136.png']['C'][0], df.loc['18575-11136.png']['A'][1], df.loc['18575-11136.png']['C'][1],), zorder=1)
ax3 = fig.add_subplot(1,3,3)
ax3.imshow(mpimg.imread('18576-11136.png'), extent=(df.loc['18576-11136.png']['A'][0], df.loc['18576-11136.png']['C'][0], df.loc['18576-11136.png']['A'][1], df.loc['18576-11136.png']['C'][1],), zorder=1)

pip install exifread<jupyter_output>Collecting exifread
[?25l  Downloading https://files.pythonhosted.org/packages/c7/72/f2b2ec1eff473108c909eaa17e89fb065d209c18b051c82844fd6da4dab5/ExifRead-2.3.1-py3-none-any.whl (40kB)

[K     |████████                        | 10kB 29.2MB/s eta 0:00:01
[K     |████████████████▏               | 20kB 6.1MB/s eta 0:00:01
[K     |████████████████████████▎       | 30kB 7.2MB/s eta 0:00:01
[K     |████████████████████████████████| 40kB 3.2MB/s 
[?25hInstalling collected packages: exifread
Successfully installed exifread-2.3.1
{'fraction_non_alphanumeric': 0.21706208985360928, 'fraction_numerical': 0.1365471983846542, 'mean_word_length': 4.221343873517786, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '554816', 'license': 'MIT', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1695, 'n_words': 271, 'path': 'stravaparser.ipynb', 'repo_name': 'shliakhtas/ASCM', 'size': '4551'}