Beispiel #1
0
def printAgeEmbededJson():
  for line in sys.stdin:
    line = line.rstrip('\n')

    line = getJsonResponse(line)
    if not line:
      continue

    dom = json.loads(line)
    text = dom['text']

    text = rtStrip(text)
    text = quoteStrip(text)
    text = spamStrip(text);

    matchObj = yearsFilter(text)
    if matchObj:
      age = 100
      ageString = matchObj.age.strip(' ')

      # check normal digit
      dmatch = re.match(r'^\d+$', ageString)
      if dmatch:
        age = int(dmatch.group())

      # check pi-multiplied
      dmatch = re.match(r'^(\d*\.\d+)pi$', ageString, re.I)
      if dmatch:
        age = int(float(dmatch.group(1)) * 3.14)

      # now see the age and increase the count
      if age < 65 and age > 0:
        dom['user']['age'] = str(age)
        print json.dumps(dom)
Beispiel #2
0
def filter():
  for line in sys.stdin:
    line = line.rstrip('\n')

    line = logStrip(line)
    if not line:
      continue

    line = rtStrip(line)
    line = quoteStrip(line)
    line = spamStrip(line);

    matchObj = yearsFilter(line)
    if matchObj:
      print line, '\t', matchObj.age
Beispiel #3
0
def printStats():
  ageCount1_14 = 0

  ageCount15_19 = 0
  ageCount20_24 = 0

  ageCount25_34 = 0
  ageCount35_44 = 0

  ageCount45_54 = 0
  ageCount55_64 = 0

  piAgeCount = 0

  for line in sys.stdin:
    line = line.rstrip('\n')

    line = logStrip(line)
    if not line:
      continue

    line = rtStrip(line)
    line = quoteStrip(line)
    line = spamStrip(line);

    matchObj = yearsFilter(line)
    if matchObj:
      age = 100
      ageString = matchObj.age.strip(' ')

      # check normal digit
      dmatch = re.match(r'^\d+$', ageString)
      if dmatch:
        age = int(dmatch.group())

      # check pi-multiplied
      dmatch = re.match(r'^(\d*\.\d+)pi$', ageString, re.I)
      if dmatch:
        age = int(float(dmatch.group(1)) * 3.14)
        piAgeCount += 1

      # now see the age and increase the count
      if age > 0 and age < 15:
        ageCount1_14 += 1
      elif age < 20:
        ageCount15_19 += 1
      elif age < 25:
        ageCount20_24 += 1
      elif age < 35:
        ageCount25_34 += 1
      elif age < 45:
        ageCount35_44 += 1
      elif age < 55:
        ageCount45_54 += 1
      elif age < 65:
        ageCount55_64 += 1

  # print the collected results
  print "Pi ages collected:", piAgeCount

  print "1-14: " + str(ageCount1_14)
  print "15-19: " + str(ageCount15_19)
  print "20-24: " + str(ageCount20_24)
  print "25-34: " + str(ageCount25_34)
  print "35-44: " + str(ageCount35_44)
  print "45-54: " + str(ageCount45_54)
  print "55-64: " + str(ageCount55_64)