We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Trouble running command "python oledNewsFlash.py" for project News Flash Headlines



  • i'm having trouble running the command "python oledNewsFlash.py" for project News Flash Headlines; it keeps giving me this return when I enter the command.

    0_1502584121843_Screenshot_5.png

    how do I fix this?



  • @Orrin-Woodard
    Hopefully you have already replaced "your api key here" with "your valid API key" so your config.json should look like this
    cat config.json

    root@Omega-5A0F:~/oled-news-flash# cat config.json
    {
        "X-API-KEY" : "your valid API key",
        "source" : "reuters",
        "sortBy" : "latest"
    }
    

    Probably the "source" : ... line is empty or not valid (valid news sources for example "reuters" or "cnn" or "hacker-news" ...).

    vi is the default editor on Omega2(+). You may install for example nano if vi is too strange for you:
    opkg update
    opkg install nano
    nano config.json

    Edit the file, Write Out (save it) with Ctrl+o hit Enter and Exit with Ctrl+x.
    Check it again with cat config.json

    Or you might use the web based Onion Console's Editor App 😉
    Onion Omega2 Documentation Developing using the Console

    Good luck!



  • @György-Farkas I did change the api key and the source key. any other ideas?



  • @Orrin-Woodard said in Trouble running command "python oledNewsFlash.py" for project News Flash Headlines:

    I did change the api key and the source key. any other ideas?

    It's time to start software testing, troubleshooting, debugging... 😉
    Do it yourself or do ask the author (James Liu) or one of Onion Omega2 Project Book Vol. 1 software experts:
    @Lazar-Demin @Gabriel-Ongpauco @Zheng-Han

    /usr/lib/python2.7/site-packages/urllib3/connectionpool.py:843: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised.
    

    Making unverified HTTPS requests is strongly discouraged, however, if you understand the risks and wish to disable these warnings, you can use disable_warnings()
    / urllib3 about SSL Warnings/

    oledNewsFlash.py
    import os
    import json
    import urllib3
    urllib3.disable_warnings()
    from OmegaExpansion import oledExp
    ...


    Traceback (most recent call last):
      File "oledNewsFlash.py", line 81, in <module>
        latest['author']
      File "oledNewsFlash.py", line 18, in WriteHeadline
        oledExp.write(author)
    TypeError: argument 1 must be string, not None
    

    My previous 'config.json' idea (guess) was wrong.
    This error occurs if the program get some response without 'author' and/or 'publishedAt' (date):

    "bad" news examples

    {u'description': u'Welcome to the new f.lux', u'title': u'Welcome to the new f.lux', u'url': u'https://justgetflux.com/news/pages/v4/bigupdate/?v=4.43', u'author': None, u'publishedAt': None, u'urlToImage': u'https://justgetflux.com/flux-icon-big.png'}

    Welcome to the new f.lux
    None
    None

    {u'description': u'Passman', u'title': u'Passman: open source password manager for Nextcloud/ownCloud', u'url': u'https://passman.cc/', u'author': u'Passman Team', u'publishedAt': None, u'urlToImage': None}

    Passman: open source password manager for Nextcloud/ownCloud
    None
    Passman Team

    where None is not a string - it's simply none

    a "good" news example

    {u'description': u'As more and more people listen to podcasts, how can podcast makers make money from what they do?', u'title': u"'I turned my dad's erotic novel into a hit podcast'", u'url': u'http://www.bbc.co.uk/news/business-40012677', u'author': u'Suzanne Bearne', u'publishedAt': u'2017-06-01T08:55:05Z', u'urlToImage': u'https://ichef-1.bbci.co.uk/news/1024/cpsprodpb/646C/production/_96180752_dsc_8556.jpg'}

    'I turned my dad's erotic novel into a hit podcast'
    2017-06-01T08:55:05Z
    Suzanne Bearne

    Unfortunately I haven't got any OLED Expansion so I can't completely test this oledNewsFlash.py masterpiece.



  • @Orrin-Woodard said in Trouble running command "python oledNewsFlash.py" for project News Flash Headlines:

    ... any other ideas?

    This is the original oledNewsFlash.py by thepiper (James Liu)
    I've made some simple modifications. download

    • Against urllib3 SSL Warnings
    /usr/lib/python2.7/site-packages/urllib3/connectionpool.py:843: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised.
    

    urllib3.disable_warnings()

    • Against 'author': None and/or 'publishedAt': None
    Traceback (most recent call last):
      File "oledNewsFlash.py", line 81, in <module>
        latest['author']
      File "oledNewsFlash.py", line 18, in WriteHeadline
        oledExp.write(author)
    TypeError: argument 1 must be string, not None
    
    
        # writes the authors at the bottom - might overflow back to page 0
        if author == None:
            author = "author n/a"
    
    
        # writes timestamp at the end to ensure it doesn't get overwritten
        if time == None:
            time = "timestamp n/a"
    

    It's very frequent on "hacker-news" 😉

    • Against "sortBy" : "latest"
    Traceback (most recent call last):
      File "oledNewsFlash.py", line 72, in <module>
        latest = newsJson['articles'][0]
    KeyError: 'articles'
    

    On certain "source" : "bbc-news" ("cnn", "google-news", ...) you should use the "sortBy" : "top" parameter instead of "sortBy" : "latest".

    config.json
    
    {
        "X-API-KEY" : "your valid API key",
        "source" : "cnn",
        "sortBy" : "top"
    }
    

    I haven't got any Oled Expansion - so any feedback would be nice. 🙂

    Thank you,
    gf.

    [0_1502917198127_oledNewsFlash.py](Uploading 100%)



Looks like your connection to Community was lost, please wait while we try to reconnect.