Python Forum
Importing photos from smartphone
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing photos from smartphone
#1
Hi, I want my script to import photos from my smartphone, to the raspberry pi.
My code looks like this:
import glob, shutil

source = "mtp://[usb:001,025]/Phone/Pictures/Ballons" and "mtp://[usb:001,025]/Phone/Pictures/Familie" and "mtp://[usb:001,025]/Phone/Pictures/Florida" and "mtp://[usb:001,025]/Phone/Pictures/Ramona" and "mtp://[usb:001,025]/Phone/Pictures/Screenshots"
dest = "/home/pi/Desktop/Photos"

for file in glob.glob(source + "/*.jpg"):
    shutil.copy(file, dest)
I don't see any problem in it, but when I run it nothing happens.
Does anyone have an idea what I did wrong?
Reply
#2
See this answer. anding strings, you end up with source having the last value in your expression.
You have to place your URLs into a list and iterate over all locations - or just use os.walk()

for loc, _, files in os.walk('mtp://[usb:001,025]/Phone/Pictures'):
     for file_name in files:
          if file_name.endswith('jpg'):
               shutil.copy(os.path.join(loc, file_name), dest)
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#3
(Apr-23-2017, 07:34 PM)volcano63 Wrote: See this answer. anding strings, you end up with source having the last value in your expression.

Evidence:

>>> files = "left" and "middle" and "right"
>>> files
'right'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Rename multiple photos with DateTimeOriginal timestamp Stjude1982 2 1,165 Oct-21-2022, 12:24 AM
Last Post: Pedroski55
Photo Moving 2 photos from each subfolder to another folder Blacklonewolf 1 2,059 Oct-28-2021, 04:07 PM
Last Post: DeaD_EyE
  Reading Smartphone Battery Level via Bluetooth maxwell 1 2,192 Jun-17-2020, 12:48 AM
Last Post: Larz60+
  sending sms messages from your smartphone skorost5 4 2,903 Apr-02-2020, 07:00 PM
Last Post: skorost5
  inserting photos in 1 sheet of a 6 sheet excel file fails Pedroski55 0 2,386 Mar-03-2018, 01:53 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020