title: Extract date from apache/niginx userid cookie
body: <p>Both webservers Apache and Nginx can give visitors uniqid cookie with mod_unique_id/userid modules. Such a <a href="http://httpd.apache.org/docs/current/mod/mod_unique_id.html" rel="nofollow noreferrer">cookie looks like</a> four uint32 values encoded to base64 string. Second byte is a timestamp when the cookie was issued.</p>
  
  <p>I'd like to extract the date and time of it.</p>
  
  <pre><code>from base64 import b64decode
  from datetime import datetime
  import shlex, gzip, glob
  from struct import unpack
  
  import pandas as pd
  import numpy as np
  
  
  def get_data() -&gt; pd.DataFrame:
      filenames = glob.glob('data/user_cookie/stat-*.gz')
      for filename in filenames:
          print(filename)
          f = gzip.open(filename, 'rt')
          for row in f.readlines():
              parts = shlex.split(row)
              useragent, raw_cookie = parts[9], parts[16]
              if raw_cookie == '-':
                  raw_visit_date = parts[3][1:]
                  # this is a first visit
                  visit_date = datetime.strptime(raw_visit_date,
                                                 '%d/%b/%Y:%H:%M:%S')
              else:
                  visit_date = datetime.fromtimestamp(unpack('IIII',
                                                             b64decode(raw_cookie))[1])
              print(useragent, visit_date)
  
  
  if __name__ == '__main__':
      get_data()
  </code></pre>
  
  <p>This line seems to me especially "artificial". How to make all code  more "pythonic" and faster?</p>
  
  <pre><code>datetime.fromtimestamp(unpack('IIII', b64decode(raw_cookie))[1])
  </code></pre>