Skip to content

Commit

Permalink
add unique IPs and users + count
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlaltdev committed Feb 10, 2018
1 parent ee76e65 commit cdfa7ab
Show file tree
Hide file tree
Showing 16 changed files with 3,398 additions and 4 deletions.
6 changes: 2 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
src/IPs.log filter=lfs diff=lfs merge=lfs -text
src/users.log filter=lfs diff=lfs merge=lfs -text
archives/users.log.tar.gz filter=lfs diff=lfs merge=lfs -text
archives/IPs.log.tar.gz filter=lfs diff=lfs merge=lfs -text
src/ filter=lfs diff=lfs merge=lfs -text
archives/ filter=lfs diff=lfs merge=lfs -text
9 changes: 9 additions & 0 deletions archive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

tar -czvf archives/IPs.log.tar.gz src/IPs.log
tar -czvf archives/unique.IPs.log.tar.gz src/unique.IPs.log
tar -czvf archives/unique.IPs.count.log.tar.gz src/unique.IPs.count.log

tar -czvf archives/users.log.tar.gz src/users.log
tar -czvf archives/unique.users.log.tar.gz src/unique.users.log
tar -czvf archives/unique.users.count.log.tar.gz src/unique.users.count.log
Binary file modified archives/IPs.log.tar.gz
Binary file not shown.
Binary file added archives/unique.IPs.count.log.tar.gz
Binary file not shown.
Binary file added archives/unique.IPs.log.tar.gz
Binary file not shown.
Binary file added archives/unique.users.count.log.tar.gz
Binary file not shown.
Binary file added archives/unique.users.log.tar.gz
Binary file not shown.
Binary file modified archives/users.log.tar.gz
Binary file not shown.
8 changes: 8 additions & 0 deletions dedupe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/python3

IPs = open("src/IPs.log").readlines()
uniqueIPs = set(IPs)
open("src/unique.IPs.log", "w").writelines(uniqueIPs)
users = open("src/users.log").readlines()
uniqueUsers = set(users)
open("src/unique.users.log", "w").writelines(uniqueUsers)
Empty file modified fetch.sh
100644 → 100755
Empty file.
14 changes: 14 additions & 0 deletions order.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

python3 ./dedupe.py

rm src/unique.IPs.count.log
rm src/unique.users.count.log

while IFS= read -r line; do count=$(grep -c "$line" src/IPs.log); echo $line:$count >> src/unique.IPs.count.log; done < src/unique.IPs.log

while IFS= read -r line; do count=$(grep -Pc "\A$line$" src/users.log); echo $line:$count >> src/unique.users.count.log; done < src/unique.users.log

python3 ./sort.py

echo DONE
25 changes: 25 additions & 0 deletions sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/python3

from operator import itemgetter

IPs = open("src/unique.IPs.count.log").readlines()

IPcounts = []
for IP in IPs:
ip, count = IP.split(":")
IPcounts.append((ip, int(count)))

with open("src/unique.IPs.count.log", "w") as IPsfile:
for ip, count in sorted(IPcounts, key=itemgetter(1), reverse=True):
IPsfile.write("{}:{}\n".format(ip, count))

users = open("src/unique.users.count.log").readlines()

Usercounts = []
for user in users:
u, count = user.split(":")
Usercounts.append((u, int(count)))

with open("src/unique.users.count.log", "w") as Usersfile:
for u, count in sorted(Usercounts, key=itemgetter(1), reverse=True):
Usersfile.write("{}:{}\n".format(u, count))
Loading

0 comments on commit cdfa7ab

Please sign in to comment.