Skip to content

Instantly share code, notes, and snippets.

@muxueqz
Created July 23, 2015 03:26
Show Gist options
  • Select an option

  • Save muxueqz/3e57baf30e35c697418e to your computer and use it in GitHub Desktop.

Select an option

Save muxueqz/3e57baf30e35c697418e to your computer and use it in GitHub Desktop.
import re
dic = {}
with open ('access_log.txt') as fh:
lines = fh.readlines()
for item in lines:
time = re.search(r'\d\d\/\w{3}\/\d{4}\:\d\d', item).group()
#print time.group()
#hour = re.search(r'\d\d\:\d\d\s$',item)
hour = time.split(':')[1]
# dic[time] = hour
dic[hour] = dic.get(hour, 0) + 1
#sorteddic = sorted(dic, key = lambda x: len(dic[x]), reverse = True)
print dic
sorteddic = sorted(dic, key = lambda x: dic[x], reverse = True)
for i in sorteddic:
print dic[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment