omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Help a beginner

    Editorial
    2
    3
    25789
    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.
    • Jozh
      Jozh last edited by

      Can someone help my change this code. I would like to have the birthday list be set as a variable so I can use it later in a workflow. Also would like to be able to set the number of upcoming birthdays that the script outputs. Thanks

      import contacts
      from datetime import datetime
      import operator
      
      days_list = []
      people = contacts.get_all_people()
      now = datetime.now()
      for p in people:
        b = p.birthday
        if b:
          next_birthday = datetime(now.year, b.month, b.day)
          if next_birthday < now:
            next_birthday = datetime(now.year + 1, b.month, b.day)
          days = (next_birthday - now).days
          days_list.append({'name': p.full_name, 'days': days})
      
      if not days_list:
        print 'You don\'t have any birthdays in your address book.'
      else:
        days_list.sort(key=operator.itemgetter('days'))
        print 'Upcoming Birthdays'
        print '=' * 40
        for item in days_list:
          print '* %s in %i days' % (item['name'], item['days'])
      

      Discussion started with RV: Forums New Discussion workflow

      1 Reply Last reply Reply Quote 0
      • zrzka
        zrzka last edited by

        Two options ...

        Variable

        Add Set Variable action before you run your script and set it to empty value. Just to have this variable. And in your Python script do this:

        import workflow
        ...
        workflow.set_variable('my_var_name', 'my_var_value')
        

        Without Set Variable action you're not able to set variable value from within your Python script. In other words, before you set it, it must exists.

        Output

        You can pass your value as an output in this way.

        import workflow
        ...
        workflow.set_output('my_var_value')
        

        String

        When you check set_output docs, you must pass str there. If you want to pass dict, list, ... or whatever, you can use json for example.

        import workflow
        import json
        
        days_list = [ ... ]
        workflow.set_output(json.dumps(days_list))
        

        And later, in other script, you can get your list back with.

        import workflow
        import json
        
        days_list = json.loads(workflow.get_input())
        ... or ...
        days_list = json.loads(workflow.get_variable('my_var_name'))
        

        But it really depends on what your goal is, workflow structure, ... These are just general comments how to ...

        1 Reply Last reply Reply Quote 0
        • Jozh
          Jozh last edited by

          Thanks for the help

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors