I am trying to write a python script for downloading videos fixing the format and download location for all videos.
This works, when download location is not specified.
import youtube_dl
link='https://www.youtube.com/watch?v=d_Bwg-dyOHI'
opts=['-f 22',link]
youtube_dl.main(opts)
this gives error ,when download location is added.Kindly correct if any changes to be made.
import youtube_dl
link='https://www.youtube.com/watch?v=d_Bwg-dyOHI'
opts=['-f 22','-o "D:Temp/video.mp4"' ,link]
youtube_dl.main(opts)
You can use os.chdir:
import youtube_dl
import os
os.chdir('/path/')
link = 'https://www.youtube.com/watch?v=d_Bwg-dyOHI'
opts = ['-f 22',link]
youtube_dl.main(opts)
Try this:
ydl_opts = {
'outtmpl': 'C:\\Users\\User\\Desktop\\%(title)s.%(ext)s',
}
Also, opts should be a dictionary.
Related
I have a python script which moves file from local dir to a gs:// using os.system. I need to pass today's date to the filename in the gcs bucket.
Here is the script:
#!/usr/bin/python
import time
import requests
import csv
import json
import os
from datetime import date
#current_date = date.today()
def uploadfile2GCSraw():
current_date = date.today()
os. system('gsutil cp /u/y/XXXX/abcd.json gs://XXXX/XX/XX/CRE_DT=current_date')
Im very new to python, when i run the above, the file is created as cre_dt=current_date, as is. its not taking the date from date.today(). Can someone help? Thanks
When you have current_date on that final line, it's going to literally be the string current_date.
Try using an f-string, like this:
os.system(f"gsutil cp /u/y/XXXX/abcd.json gs://XXXX/XX/XX/CRE_DT={current_date}")
For older python 2, use this syntax:
os.system("gsutil cp /u/y/XXXX/abcd.json gs://XXXX/XX/XX/CRE_DT=%s"%(date.today()))
(And then upgrade to Python 3.)
Should do what you want.
I'm new to this, and trying to download a snappy.parquet file from Amazon s3 I can later convert to CSV file.
I tried working with the following example I've found online, and I get an empty folder. can anyone please help me?
import boto
import sys, os
from boto.s3.key import Key
from boto.exception import S3ResponseError
DOWNLOAD_LOCATION_PATH =""
BUCKET_NAME = ""
AWS_ACCESS_KEY_ID= ""
AWS_ACCESS_SECRET_KEY = ""
conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_ACCESS_SECRET_KEY)
bucket = conn.get_bucket(BUCKET_NAME)
#goto through the list of files
bucket_list = bucket.list()
for l in bucket_list:
key_string = str(l.key)
s3_path = DOWNLOAD_LOCATION_PATH + key_string
try:
print ("Current File is ", s3_path)
l.get_contents_to_filename(s3_path)
except (OSError, S3ResponseError) as e:
pass
# check if the file has been downloaded locally
if not os.path.exists(s3_path):
try:
os.makedirs(s3_path)
except OSError as exc:
# let guard againts race conditions
import errno
if exc.errno != errno.EEXIST:
raise
The script you are using appears to recursively download the contents of the specified S3 bucket (BUCKET_NAME) to the specified local directory (DOWNLOAD_LOCATION_PATH). FWIW, I notice this script looks like it comes from here.
The "Current File is ..." output line should show you the progress of these files being written. One problem you might be having is due to this line:
s3_path = DOWNLOAD_LOCATION_PATH + key_string
If you had specified DOWNLOAD_LOCATION_PATH at the top as a directory without a trailing '/' character, e.g. like this:
DOWNLOAD_LOCATION_PATH = '/tmp/my_dir'
then the files being downloaded would be written not underneath the /tmp/my_dir directory, but directly in /tmp/ with a my_dir prefix on each filename! You can fix this by changing this line to:
s3_path = os.path.join(DOWNLOAD_LOCATION_PATH, key_string)
Other than that, the script appears to work alright. You may want to add this line at the very top:
from __future__ import print_function
if you are still using Python 2.x, otherwise the print output will look a bit odd (print will think you are printing a 2-Tuple).
Your question also makes it sound like you really only want/need to download a single file from the bucket -- if so, this isn't really a great script to be using, since it's downloading everything.
Hello sorry if this question has been asked before.
But I have tried a lot of methods that provided.
Basically, I want to download the file from a website, which is I will show my coding below. The code works perfectly, but the problem is the file was auto download in our download folder path directory.
My concern is to download the file and save it to a specific folder.
I'm aware we can change our browser setting since this was a server that will remote by different users. So, it will automatically download to their temporarily /users/adam_01/download/ folder.
I want it to save in server disk which is, C://ExcelFile/
Below are my script and some of the data have been changing because it is confidential.
import pandas as pd
import html5lib
import time from bs4
import BeautifulSoup
import requests
import csv
from datetime
import datetime
import urllib.request
import os
with requests.Session() as c:
proxies = {"http": "http://:911"}
url = 'https://......./login.jsp'
USERNAME = 'mwirzonw'
PASSWORD = 'Fiqr123'
c.get(url,verify= False)
csrftoken = ''
login_data = dict(proxies,atl_token = csrftoken, os_username=USERNAME, os_password=PASSWORD, next='/')
c.post(url, data=login_data, headers={"referer" : "https://.....com"})
page = c.get('https://........s...../SearchRequest-96010.csv')
location = 'C:/Users/..../Downloads/'
with open('asdsad906010.csv', 'wb') as output:
output.write(page.content )
print("Done!")
Thank you, be pleased to ask if any confusing information was given.
Regards,
Fiqri
It seems that from your script you are writing the file to asdsad906010.csv. You should be able to change the output directory as follows.
# Set the output directory to your desired location
output_directory = 'C:/ExcelFile/'
# Create a file path by joining the directory name with the desired file name
file_path = os.path.join(output_directory, 'asdsad906010.csv')
# Write the file
with open(file_path, 'wb') as output:
output.write(page.content)
I want to plot my gps data on google maps using python. I searched & found that pygmaps does the thing but I'm getting error when I import this file it says "'module' object has no attribute 'maps'". I've saved this file in libs folder in python27 in c drive. What should i do now ?
import pygmaps
mymap = pygmaps.maps(18.458184, 73.850781, 14)
mymap.addpoint(18.458184, 73.850781, '#0000FF')
mymap.draw('./mymap.html')
As I understand your code should be like the following:
import pygmaps
mymap = pygmaps.pygmaps(18.458184, 73.850781, 14)
mymap.addpoint(18.458184, 73.850781, '#0000FF')
mymap.draw('./mymap.html')
I try to find a simple python code that convert hundred of pdf files to jpg files to the same folder where the pdf files located. I use this code from Python Wand converts from PDF to JPG background is incorrect
from wand.image import Image
from wand.color import Color
import os, os.path, sys
def pdf2jpg(source_file, target_file, dest_width, dest_height):
RESOLUTION = 300
ret = True
try:
with Image(filename=source_file, resolution=(RESOLUTION,RESOLUTION)) as img:
img.background_color = Color('white')
img_width = img.width
ratio = dest_width / img_width
img.resize(dest_width, int(ratio * img.height))
img.format = 'jpeg'
img.save(filename = target_file)
except Exception as e:
ret = False
return ret
if __name__ == "__main__":
source_file = r"C:\Users\yaron.KAYAMOT\Desktop\aaa.pdf"
target_file = r"C:\Users\yaron.KAYAMOT\Desktop\aaa.jpg"
ret = pdf2jpg(source_file, target_file, 1895, 1080)
but i get an error:
ImportError: MagickWand shared library not found.
You probably had not installed ImageMagick library.
Try to install:
http://docs.wand-py.org/en/latest/guide/install.html#install-imagemagick-on-windows
>>>
but i do have module MagickWand in the hard disk as shown in the cmd :
UPDATE:
when i try to pip install in the cmd "wand" module i get:
so,i do have this module. When i try to pip install imagemagick \ ImageMagick i get:
You're importing from wand module.
You probably haven't installed bindings for Python.
pip install Wand
See the details here: http://docs.wand-py.org/en/0.4.2/
Also try to do the following:
pip search pythonmagick
or something like that. Try to install all required packages.
This may help you.