Coder Social home page Coder Social logo

Comments (10)

waveform80 avatar waveform80 commented on May 26, 2024

Can you post the code you're using?

from compoundpi.

mananwason avatar mananwason commented on May 26, 2024

Sure. This is the code I'm running. Just basic capturing and downloading.

from compoundpi.client import CompoundPiClient
import io
client = CompoundPiClient()
try:
        client.servers.network = '192.168.43.1/24'
        #client.servers.output = '/home/manan/Desktop/captures'
        client.servers.find(10)
        client.capture()
    for addr, files in client.list().items():
         for f in files:
            print('Downloading image %d from %s (%d bytes)' % (
                f.index,
                addr,
                f.size,
                ))
            with io.open('%s-%d.jpg' % (addr, f.index)) as f:
                client.download(addr, f.index, f)
finally:
    client.clear()  
    client.close()

from compoundpi.

waveform80 avatar waveform80 commented on May 26, 2024

Ah, you're missing the file mode in io.open. This defaults to 'r' (read) so you're attempting to open "192.168.43.171-0.jpg" for reading and, naturally, it doesn't exist so you wind up with a no such file or directory error. Just add a 'wb' parameter to the io.open call and you should be good to go.

from compoundpi.

mananwason avatar mananwason commented on May 26, 2024

Oh this is solved the problem but another I got another one now. It prints the index but shows this error as well.

AttributeError: '_io.BufferedWriter' object has no attribute 'index'

This is while download using client.download(addr, f.index, f)

from compoundpi.

waveform80 avatar waveform80 commented on May 26, 2024

Ah indeed - you've called the open file object f which overwrites the file metadata object f. Hence, when it goes to look for f.index within the with clause you get an attribute error. I'd suggest calling the open file object something else (have a look at the first example in http://compoundpi.readthedocs.org/en/release-0.4/batch.html#examples which uses "output" as the name instead)

from compoundpi.

mananwason avatar mananwason commented on May 26, 2024

Oh yeah. That was the issue. Now it is working fine. But I also need the epoch time in the name of the file. How can I do that?

from compoundpi.

waveform80 avatar waveform80 commented on May 26, 2024

Assuming by "epoch time" you mean "seconds since the UNIX epoch" (i.e. a UNIX timestamp), f.timestamp will contain the capture timestamp as a datetime object so you could do something like:

with io.open('%s-%d-%d.jpg' % (addr, f.index, f.timestamp.timestamp())) as output:
    client.download(addr, f.index, output)

from compoundpi.

mananwason avatar mananwason commented on May 26, 2024

I had tried doing this earlier but what I got was
AttributeError: 'datetime.datetime' object has no attribute 'timestamp'
I googled it but didn't find any conclusive answers.

from compoundpi.

waveform80 avatar waveform80 commented on May 26, 2024

Are you perhaps using Python 2? The timestamp method for datetime objects was only added in Python 3. In Python 2 you'd need to do something like:

from time import mktime

...

with io.open('%s-%d-%d.jpg' % (addr, f.index, mktime(f.timestamp.timetuple()))) as output:
    client.download(addr, f.index, output)

from compoundpi.

mananwason avatar mananwason commented on May 26, 2024

oh yeah !! Thanks for your help!!

from compoundpi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.