how can I refactor this py2neo v4 code to use neo4j 3.4 temporal data types?










1















I'm stuck trying to add a date_accepted property to an upload node that represents a scientific paper. Previously, I would have just added a timetree node. However, py2neo v4 no longer supports GregorianCalendar (shame). How would I convert this code snippet to use one of the new temporal data types? I've looked at the docs & online but I'm not yet savvy enough I'm afraid.



from datetime import date, datetime # ??? how to use this...

def getAccepted(year_accepted, month, day):
with open('/home/pmy/pdf/id.txt') as f:
id = f.read()
matcher = NodeMatcher(graph)
upload = matcher.match("Upload", id = id).first()

a = year_accepted+month+day
d = datetime.strptime(a, '%Y%m%d').strftime('%Y-%m-%d')
# >>> HOW TO CONVERT d TO A TEMPORAL DATA TYPE HERE? <<<
try:
graph.merge(upload)
upload['accepted_date']=d
graph.push(upload)

except IndexError as e:
print("type error: " + str(e))
pass
return 0


This works but it pushes the datetime string whereas I want to push a neotime temporal date...



It is possible to insert the datetime variable d above into something like this query below, which also works, but I'm winging this & suspect there's a better way...



query='''UNWIND [date(param)] AS date RETURN date'''
result=graph.run(query, param=d).data()
print(result)


which returns



['date': neotime.Date(2010, 10, 23)]


So I could maybe extract the value & push that to the graph? Is this what the developers intended? The Docs are terse and aimed at proper programmers so IDK



Maybe



 accepted=result[0].get('date') # <class 'neotime.Date'>


& push that to the graph perhaps?



The py2neo v4 neotime temporal types are very recent & there is not much documentation, or basic tutorials to adapt afaik. Hence this long-winded post. Anyone out there with experience care to comment?










share|improve this question




























    1















    I'm stuck trying to add a date_accepted property to an upload node that represents a scientific paper. Previously, I would have just added a timetree node. However, py2neo v4 no longer supports GregorianCalendar (shame). How would I convert this code snippet to use one of the new temporal data types? I've looked at the docs & online but I'm not yet savvy enough I'm afraid.



    from datetime import date, datetime # ??? how to use this...

    def getAccepted(year_accepted, month, day):
    with open('/home/pmy/pdf/id.txt') as f:
    id = f.read()
    matcher = NodeMatcher(graph)
    upload = matcher.match("Upload", id = id).first()

    a = year_accepted+month+day
    d = datetime.strptime(a, '%Y%m%d').strftime('%Y-%m-%d')
    # >>> HOW TO CONVERT d TO A TEMPORAL DATA TYPE HERE? <<<
    try:
    graph.merge(upload)
    upload['accepted_date']=d
    graph.push(upload)

    except IndexError as e:
    print("type error: " + str(e))
    pass
    return 0


    This works but it pushes the datetime string whereas I want to push a neotime temporal date...



    It is possible to insert the datetime variable d above into something like this query below, which also works, but I'm winging this & suspect there's a better way...



    query='''UNWIND [date(param)] AS date RETURN date'''
    result=graph.run(query, param=d).data()
    print(result)


    which returns



    ['date': neotime.Date(2010, 10, 23)]


    So I could maybe extract the value & push that to the graph? Is this what the developers intended? The Docs are terse and aimed at proper programmers so IDK



    Maybe



     accepted=result[0].get('date') # <class 'neotime.Date'>


    & push that to the graph perhaps?



    The py2neo v4 neotime temporal types are very recent & there is not much documentation, or basic tutorials to adapt afaik. Hence this long-winded post. Anyone out there with experience care to comment?










    share|improve this question


























      1












      1








      1


      1






      I'm stuck trying to add a date_accepted property to an upload node that represents a scientific paper. Previously, I would have just added a timetree node. However, py2neo v4 no longer supports GregorianCalendar (shame). How would I convert this code snippet to use one of the new temporal data types? I've looked at the docs & online but I'm not yet savvy enough I'm afraid.



      from datetime import date, datetime # ??? how to use this...

      def getAccepted(year_accepted, month, day):
      with open('/home/pmy/pdf/id.txt') as f:
      id = f.read()
      matcher = NodeMatcher(graph)
      upload = matcher.match("Upload", id = id).first()

      a = year_accepted+month+day
      d = datetime.strptime(a, '%Y%m%d').strftime('%Y-%m-%d')
      # >>> HOW TO CONVERT d TO A TEMPORAL DATA TYPE HERE? <<<
      try:
      graph.merge(upload)
      upload['accepted_date']=d
      graph.push(upload)

      except IndexError as e:
      print("type error: " + str(e))
      pass
      return 0


      This works but it pushes the datetime string whereas I want to push a neotime temporal date...



      It is possible to insert the datetime variable d above into something like this query below, which also works, but I'm winging this & suspect there's a better way...



      query='''UNWIND [date(param)] AS date RETURN date'''
      result=graph.run(query, param=d).data()
      print(result)


      which returns



      ['date': neotime.Date(2010, 10, 23)]


      So I could maybe extract the value & push that to the graph? Is this what the developers intended? The Docs are terse and aimed at proper programmers so IDK



      Maybe



       accepted=result[0].get('date') # <class 'neotime.Date'>


      & push that to the graph perhaps?



      The py2neo v4 neotime temporal types are very recent & there is not much documentation, or basic tutorials to adapt afaik. Hence this long-winded post. Anyone out there with experience care to comment?










      share|improve this question
















      I'm stuck trying to add a date_accepted property to an upload node that represents a scientific paper. Previously, I would have just added a timetree node. However, py2neo v4 no longer supports GregorianCalendar (shame). How would I convert this code snippet to use one of the new temporal data types? I've looked at the docs & online but I'm not yet savvy enough I'm afraid.



      from datetime import date, datetime # ??? how to use this...

      def getAccepted(year_accepted, month, day):
      with open('/home/pmy/pdf/id.txt') as f:
      id = f.read()
      matcher = NodeMatcher(graph)
      upload = matcher.match("Upload", id = id).first()

      a = year_accepted+month+day
      d = datetime.strptime(a, '%Y%m%d').strftime('%Y-%m-%d')
      # >>> HOW TO CONVERT d TO A TEMPORAL DATA TYPE HERE? <<<
      try:
      graph.merge(upload)
      upload['accepted_date']=d
      graph.push(upload)

      except IndexError as e:
      print("type error: " + str(e))
      pass
      return 0


      This works but it pushes the datetime string whereas I want to push a neotime temporal date...



      It is possible to insert the datetime variable d above into something like this query below, which also works, but I'm winging this & suspect there's a better way...



      query='''UNWIND [date(param)] AS date RETURN date'''
      result=graph.run(query, param=d).data()
      print(result)


      which returns



      ['date': neotime.Date(2010, 10, 23)]


      So I could maybe extract the value & push that to the graph? Is this what the developers intended? The Docs are terse and aimed at proper programmers so IDK



      Maybe



       accepted=result[0].get('date') # <class 'neotime.Date'>


      & push that to the graph perhaps?



      The py2neo v4 neotime temporal types are very recent & there is not much documentation, or basic tutorials to adapt afaik. Hence this long-winded post. Anyone out there with experience care to comment?







      neo4j py2neo






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 16:50







      user1613312

















      asked Nov 15 '18 at 12:05









      user1613312user1613312

      11911




      11911






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319135%2fhow-can-i-refactor-this-py2neo-v4-code-to-use-neo4j-3-4-temporal-data-types%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319135%2fhow-can-i-refactor-this-py2neo-v4-code-to-use-neo4j-3-4-temporal-data-types%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3