MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    save some information from a xml or json to a txt file

    Scheduled Pinned Locked Moved Requests
    25 Posts 5 Posters 18.1k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • LukeCodewalkerL Offline
      LukeCodewalker Module Developer
      last edited by

      Now it should work

      #!/usr/bin/python
      # -*- coding: utf-8 -*-
      import codecs
      import json
      import subprocess
      
      APP_ID = ''
      FILE_PATH = 'test.txt'
      
      url = 'http://api.openweathermap.org/data/2.5/weather?id=2934486&lang=de&units=metric&mode=json&appid=' + APP_ID
      curl_req = 'curl -L ' + '"' + url + '"'
      p = subprocess.Popen(curl_req, stdout=subprocess.PIPE, shell=True)
      (output, err) = p.communicate()  
      p_status = p.wait()
      
      try:
          decoded = json.loads(output)
          weather = decoded['weather'][0]['description']
          temp = decoded['main']['temp']
          f = codecs.open(FILE_PATH,'w', 'utf-8')
          f.write('Today is ' + weather + ' and ' + str(temp) + ' degrees.')
          f.close()
      except (ValueError, KeyError, TypeError):
          pass
      
      1 Reply Last reply Reply Quote 0
      • G Offline
        gismo2006
        last edited by

        Hi, a big thank you!!

        Its work perfect!!!

        Many Thanks! :-)

        greets gismo

        morozgrafixM 1 Reply Last reply Reply Quote 0
        • LukeCodewalkerL Offline
          LukeCodewalker Module Developer
          last edited by

          Welcome :)

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            Squirrel @LukeCodewalker
            last edited by

            @LukeCodewalker i want to make the same Module for Switzerland but i don`t know how to find the json data for my region…

            Can you help me please? ;) I found your link in the node_helper.js file. From where do you got that?

            I would like o work with http://alarm.meteocentrale.ch/

            LukeCodewalkerL 2 Replies Last reply Reply Quote 0
            • LukeCodewalkerL Offline
              LukeCodewalker Module Developer @Squirrel
              last edited by

              @Squirrel
              i did some reverse engineering of the dwd-website and found this json file.
              i had a short look at your link and did not found something similar there. do you know if theres an app for ios where the data is shown? maybe i can help you then.

              1 Reply Last reply Reply Quote 0
              • LukeCodewalkerL Offline
                LukeCodewalker Module Developer @Squirrel
                last edited by

                @Squirrel
                maybe this link helps you:
                https://s3-eu-central-1.amazonaws.com/app-prod-static-fra.meteoswiss-app.ch/v1/warnings_with_outlook_with_naturalhazards_de.json

                1 Reply Last reply Reply Quote 0
                • S Offline
                  Squirrel
                  last edited by Squirrel

                  @LukeCodewalker Thx for the answer. I will try it out. At the moment i can`t find my City. But maybe only because there is no warning at the moment? Otherwise on the alarm.meteocentrale.ch is still a warning for snow on the streets…?

                  What about wetteralarm.ch/? This is a app for iPhone and Android! Maybe it can work with this site?

                  LukeCodewalkerL 1 Reply Last reply Reply Quote 0
                  • LukeCodewalkerL Offline
                    LukeCodewalker Module Developer @Squirrel
                    last edited by

                    @Squirrel
                    I can’t download this app in germany, so I can’t have a look at the data it uses.

                    1 Reply Last reply Reply Quote 0
                    • S Offline
                      Squirrel
                      last edited by

                      Ok. Shit happens. Maybe you can tell me with which program/method u read the code of a app? The I can do it alone…

                      LukeCodewalkerL 1 Reply Last reply Reply Quote 0
                      • LukeCodewalkerL Offline
                        LukeCodewalker Module Developer @Squirrel
                        last edited by

                        @Squirrel
                        I use mitmproxy for viewing the http-requests of the apps.

                        1 Reply Last reply Reply Quote 1
                        • 1
                        • 2
                        • 3
                        • 2 / 3
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Sam, technical setup by Karsten.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy