• Drizzel

    Thanks a lot, I tried it out and it improved the data. Another interesting thing is that somehow the data seems to be more consistent when moving

    posted in Pythonista read more
  • Drizzel

    I’m trying to make a small gps logger that tells me how far I ran in a given time, but it seems as if the gps data isn’t very consistent. This is a shortened version of my code:

    import location, time, math
    def distanceFromCoords(long1, lat1, long2, lat2): #calculate distance between two coordinates
        #convert latitude and longitude to spherical coordinates in radians
        degrees_to_radians = math.pi/180.0
        #phi = 90 - latitude
        phi1 = (90.0 - lat1)*degrees_to_radians
        phi2 = (90.0 - lat2)*degrees_to_radians
        # theta = longitude
        theta1 = long1*degrees_to_radians
        theta2 = long2*degrees_to_radians
        #calculate spherical distance from spherical coordinates.
        cos = (math.sin(phi1)*math.sin(phi2)*math.cos(theta1 - theta2) + math.cos(phi1)*math.cos(phi2))
        arc = math.acos(cos)
        # multiply arc by the radius of the earth (3960 miles or 6371 kilometers)
        return round(arc*6371*1000) #multiplied with 1000 to get meters
    location.start_updates() #start location updates
    if True:
        distance = 0 #total distance travelled
        startTime = time.time() #set starting time of timer
        #to calculate distances two coordinates are needed. coord1 is the coordinate I was at, and coord2 is the coordinate I am at now
        coord2 = (location.get_location()['longitude'],location.get_location()['latitude'])
        while True: 
            coord1 = coord2 #set coord1 to coord2 from previous loop repetition
            coord2 = (location.get_location()['longitude'],location.get_location()['latitude']) #get current coordinates
            distance += distanceFromCoords(coord1[0], coord1[1], coord2[0], coord2[1]) #add distance between coord1 and coord2 to the total distance travelled
            print('\n', round(time.time()-startTime), '\n', distance, '\n')
    location.stop_updates() #I know, this never gets executed :D

    If I don’t move my iPad and leave it for twenty seconds, the code tells me that I already moved about 50 meters! When doing a cooper run (you have 12 minutes time and need to run as far as possible) these 50 meters would already change my grade substantially (yeah, I’m still in school).

    Is there any better way to do this? After all most apps (runtastic, google maps ...) manage too.

    posted in Pythonista read more
  • Drizzel

    The scene module comes natively with pythonista, and there are a few examples that might help

    posted in Pythonista read more
  • Drizzel

    Oh, and your last two lines should be:

    if __name__ == '__main__':

    This should be a working version:

    # coding: utf-8
    import twitter
    def main():
        accounts = twitter.get_all_accounts()
        if not accounts:
            print('No Twitter accounts were found. You can configure Twitter accounts in the settings app. If you have denied access to your accounts when prompted, you can also change your mind there.')
        account = accounts[0]
        username = account['username']
        print('Loading recent tweets in %s\'s timeline...' % (username,))
        tweets = twitter.get_home_timeline(account)
        for tweet in tweets:
            print('%s:\n\n%s' % (tweet['user']['screen_name'], tweet['text']))
            print('-' * 40)
    if __name__ == '__main__':

    posted in Pythonista read more
  • Drizzel

    If the code in tweet.py is exactly the same as what you showed us, you’re missing a # before the coding: utf-8. Corrected, you would have to change your first line to

    #coding: utf-8

    The # is commonly used for commenting your code in normal language, as it tells the python interpreter that the following line is no actual python code and can therefore be ignored. The interpreter makes your code understandable for machines and therefore executable also.

    If you want to know more or this is not the correct answer, just ask again and again and again 😋

    posted in Pythonista read more
  • Drizzel

    @mikael messages, as it doesn’t actually take too long and I don’t have to manage many small bits of data, making it easier for me (with limited python knowledge) to transfer multiple files.

    posted in Pythonista read more
  • Drizzel

    @cvp @JonB @mikael I did forget to decode the data after receiving it, my bad. It works flawlessly now, thanks a lot!

    posted in Pythonista read more
  • Drizzel

    I just gave it a first try, it didn’t completely work, but it was a promising start. The length of the data before sending and receiving is the same, so I’m assuming the data itself is fine. If I then write it to a file though, it’s only 719 bytes, not 4 mb as it should be. For now, I have no clue why, but as a I said it’s promising.

    posted in Pythonista read more
  • Drizzel

    @mikael I had an old version installed, so I just updated. I will definitely look into it now. It’s interesting that it apparently doesn’t require strings, which might fix the errors I’m currently fighting with :)

    @cvp I tried out your suggestion, and I now can transfer the data without getting errors! The issue I now have, is that the final file is about 2.5 times as large as the original, and it therefore won’t play. Reading in the file, converting it to a string and then writing it to a new file showed that the conversion to a string is where the data gets altered heavily, and obviously I have no idea what to do about it😂

    Any ideas?

    posted in Pythonista read more
  • Drizzel

    @cvp I tried it out, I got a different error now. It's "Object of type 'bytes' is not JSON serializable". Any idea why?

    posted in Pythonista read more
  • Drizzel

    I’ve made a multiplayer game some time ago using multipeer. Anyone who is interested can find some more information here.
    Now I wondered if I could transfer files (preferably .m4a) over it. I modified the module to store the received data in the variable “received”, so that I could access it comfortably with “multipeer.received”.

    I have tried reading files like this

    with open(“file.m4a”) as f: 
        data = f.read()

    but I always get an error that says cannot read byte at location...

    I wanted to then transfer the string with multipeer to my iPad.
    Is there any way to fix this, or could I send files from one device to another any other way?

    posted in Pythonista read more
  • Drizzel

    Impressive, thanks a lot👍

    posted in Pythonista read more
  • Drizzel

    I assume you’re in the console right now. First of all, there’s a small arrow in the top left corner, or you can alternatively swipe left and/ or right to switch between console and code. Oh, and as long as you’re asking something related to pythonista, there’s no stupid questions, just stupid answers.

    posted in Pythonista read more
  • Drizzel

    import numpy as np
    import sys
    import motion
    import matplotlib.pyplot as plt
    from time import sleep
    import console
    del g
    del ag
    del data
    del data_ag
    def main():
        console.alert('Motion Plot', 'When you tap Continue, accelerometer (motion) data will be recorded for 5 seconds.', 'Continue')
        print('Capturing motion data...')
        num_samples = fs*duration;
        data = []
        data_ag = []
        for i in range(num_samples):
            g = motion.get_gravity();
        print('Capture finished, plotting...')
        x_values = [x/fs for x in range(num_samples)]
        for i, color, label in zip(range(3), 'rgb', 'XYZ'):
            plt.plot(x_values, [g[i] for g in data], color, label=label, lw=2)
        plt.gca().set_ylim([-1.0, 1.0])

    posted in Pythonista read more
  • Drizzel

    your dataset (the variable data) is an array

    data = []

    that contains tuples, which is the variable g.

    data = [()]

    This tuple then contains 3 variables.

    data = [(5.67, 1.87, 3.93)]

    Running this code:

    for g in data:

    will print every tuple in the data array, which is (5.67, 1.87, 3.93).
    If you want to print a single float (the name for a number with decimal places), just use this:


    Replace the 0 with a 1 to print the second float in g, and 2 for the third float in g

    posted in Pythonista read more
  • Drizzel

    Whenever I try to run this basic script, I get the Error [Errno 1] Operation not permitted. It’s some example code of the pylatex module, so it should theoretically work. Or is it IOS that blocks some functions?

    This example shows basic document generation functionality.
    ..  :copyright: (c) 2014 by Jelte Fennema.
        :license: MIT, see License for more details.
    # begin-doc-include
    from pylatex import Document, Section, Subsection, Command
    from pylatex.utils import italic, NoEscape
    def fill_document(doc):
        """Add a section, a subsection and some text to the document.
        :param doc: the document
        :type doc: :class:`pylatex.document.Document` instance
        with doc.create(Section('A section')):
            doc.append('Some regular text and some ')
            doc.append(italic('italic text. '))
            with doc.create(Subsection('A subsection')):
                doc.append('Also some crazy characters: $&#{}')
    if __name__ == '__main__':
        # Basic document
        doc = Document('basic')
        # Document with `\maketitle` command activated
        doc = Document()
        doc.preamble.append(Command('title', 'Awesome Title'))
        doc.preamble.append(Command('author', 'Anonymous author'))
        doc.preamble.append(Command('date', NoEscape(r'\today')))
        doc.generate_pdf('basic_maketitle', clean_tex=False)
        # Add stuff to the document
        with doc.create(Section('A second section')):
            doc.append('Some text.')
        doc.generate_pdf('basic_maketitle2', clean_tex=False)
        tex = doc.dumps()  # The document as string in LaTeX syntax

    posted in Pythonista read more
  • Drizzel

    @BrianAz look at this. This module allows you to create shortcuts for the shortcuts app in pythonista, which is compatible with siri

    posted in General Discussion read more
  • Drizzel

    Sorry for the late reply, your answer was exactly what I needed. I tried things like self.close() and self.hide(), but I just didn’t get to the self.view.close()

    posted in Pythonista read more
  • Drizzel

    @donaldcassey yes it should work with soundcloud. I didn’t test it, but the module contains a file for extracting data from soundcloud. If you want to use this, just copy the code into a new directory and create a file called ‘songs.txt’ . Then paste every link into a new line in the text file. The code does not work if the file contains empty lines, but you can fix that with by replacing



    if not “\n” in song_url: dl.download([song_url])

    posted in Pythonista read more
  • Drizzel

    I don’t want to bore you with a ton of details, so long story short: how do I close a game that has been coded with the scene module? I don’t want to tap the little close button in the top right corner.

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!