-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfacebook.sh
More file actions
executable file
·120 lines (100 loc) · 3.18 KB
/
facebook.sh
File metadata and controls
executable file
·120 lines (100 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# -------------------------------------------------------------
#
# Title: statements about facebook posts based on a data set
#
# Requirements: awk, csvkit, csvsql, csvlook
#
# Autoren: Michael Bertschi, Jan Minder, Rehan Mirza
# Version: 1.0
# Datum: 23. Januar 2020
#
# -------------------------------------------------------------
# Variablen
TITLE="| Facebook Data Mining |"
FB_DATA="data/facebook.csv"
# Colors
MENU_COLOR="\033[36m" # cyan
DEFAULT_COLOR="\033[37m" # white
PRIMARY_COLOR="\033[32m" # green
OUTPUT_COLOR="\033[33m" # yellow
ERROR_COLOR="\033[31m" # red
# Functions
# Michi / Aufgabe 7.1
function data_preview {
#Head - 10 Show us the first ten rows from the csv sheet.
#The csvlook show us an formated table and the max.column-width
#is the max space of a column
head -10 $FB_DATA | csvlook --max-column-width 8
}
# Rehan / Aufgabe 7.2
function state_count {
# sql query to count every status_id of each status_type
# show the table of counted status_id's in each status_type
csvsql --query "select count() as status_id, status_type from facebook group by status_type" $FB_DATA | csvlook
}
# Jan / Aufgabe 7.3
function popular_post {
# calculates the column 8 - 15 of each line with awk
# sorts the output from awk based on likes column
# take the first result with head 1
# split the output with awk and add output styling
# columns with wrong data (eg. a date) will be count as 0
awk -F "\"*,\"*" '{
printf "%d|%s|%s|%s\n", int($8 + $9 + $11 + $12 + $13 + $14 + $15), $2, $1, $5
}' $FB_DATA \
| sort -gk 1 -r \
| head -1 \
| awk -v ocolor="${OUTPUT_COLOR}" -v pcolor="${PRIMARY_COLOR}" -v dcolor="${DEFAULT_COLOR}" '{
split($0,a,"|");
printf " Likes: %s%d%s\n Text: %s%s%s\n Id: %s%s%s\n Url: %s%s%s",
pcolor, a[1], dcolor, ocolor, a[2], dcolor, ocolor, a[3], dcolor, ocolor, a[4], dcolor}'
printf "\n\n"
}
# -- Menu -----------------------------------
# Der Array fuer das Menu
MENU=(
"Show data preview"
"Count of state per type"
"Show most popular post"
"End"
)
# Anzahl Elemente des Arrays MENU
ANZAHL=${#MENU[*]}
# Print Menu after each operation
while true; do
# Print Menu
printf "${MENU_COLOR}\n%s\n" "--------------------------------"
printf "$TITLE\n"
printf "%s${DEAULT_COLOR}\n\n" "--------------------------------"
for ((i=0; $i<$ANZAHL; i=$i+1)); do
printf "${MENU_COLOR} $i - ${MENU[$i]} ${DEFAULT_COLOR}\033[37m\n"
done
printf "\n"
# Read selection
echo -n "Confirm with ENTER key: "
read ANTWORT
case $ANTWORT in
0) # data preview
printf "\n${MENU_COLOR}%s${DEFAULT_COLOR}\n\n" "=> ${MENU[0]}"
data_preview
echo ""
;;
1) # state count
printf "\n${MENU_COLOR}%s${DEFAULT_COLOR}\n\n" "=> ${MENU[1]}"
state_count
;;
2) # popular post
printf "\n${MENU_COLOR}%s${DEFAULT_COLOR}\n\n" "=> ${MENU[2]}"
popular_post
;;
3|[eE]|[qQ]) # regular expression, 3, e/E, q,Q
printf "\n${PRIMARY_COLOR}%s${DEFAULT_COLOR}\n\n" "=> ${MENU[3]}"
break # exit while loop
;;
*) # any other keys
printf "\n${ERROR_COLOR}%s${DEFAULT_COLOR}\n\n" "=> Invalid Input Selection"
;;
esac
done