Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import boto3
- import MySQLdb
- import requests
- import shutil
- import subprocess, shlex
- s3 = boto3.resource('s3',
- endpoint_url = 'https://s3.wasabisys.com')
- BUCKET = "images.hizzle.me"
- db2 = MySQLdb.connect(host="127.0.0.1", # your host, usually localhost
- charset='utf8',
- user="", # your username
- passwd="", # your password
- db="") # name of the data base
- cur2 = db2.cursor()
- cur2.execute('SET NAMES utf8;')
- cur2.execute('SET CHARACTER SET utf8;')
- cur2.execute('SET character_set_connection=utf8;')
- cur2.execute("SELECT MAX(lastupdate) FROM updates WHERE name = 'images'")
- last_update = cur2.fetchone()[0]
- print "Getting records since", last_update
- cur2.execute("SELECT mediaName, tableuid, displayorder FROM media where modified >= %s and mediatype = 'PHOTO';", [last_update])
- rows = cur2.fetchall()
- for row in rows:
- url = "https://matrixmedia.northstarmls.com/MediaServer/GetMedia.ashx?Key=" + row[1] + "&TableID=1&Size=5&Type=1&Number=" + row[2]
- print("Getting image url: " + url)
- response = requests.get(url)
- media_name = row[0]
- final_path = "/home/images/2019/" + media_name
- if response.status_code == 200:
- with open(media_name, 'wb') as f:
- f.write(response.content)
- shutil.move(media_name, final_path)
- cmd = "aws s3 mv " + final_path + " s3://test1testtest11/ --include 'houses.python' --endpoint-url=https://s3.wasabisys.com"
- s3.Bucket(BUCKET).upload_file(final_path, media_name)
- print media_name, "uploaded"
- cur2.execute("INSERT INTO updates (name, lastupdatecount) VALUES (%s, %s)",("images", len(rows)))
- print "Updated date, total uploaded to bucket:", len(rows)
- db2.commit()
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement