-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplot-messages.sh
More file actions
executable file
·42 lines (35 loc) · 1.02 KB
/
plot-messages.sh
File metadata and controls
executable file
·42 lines (35 loc) · 1.02 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
#!/bin/bash
set -Eeufo pipefail
trap 'echo >&2 "$0:$LINENO [$?]: $BASH_COMMAND"' ERR
prog=$(basename "$0")
usage() {
cat <<EOS
Usage: $prog FILE.html ...
Takes HTML files from /messages/inbox in "copy of your Facebook data", parses
message timestamps from them, and plots a histogram.
EOS
}
if [[ $# -eq 0 || "$1" = "-h" || "$1" == "--help" ]]; then
usage
exit
fi
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
rg '>((?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Nov|Dec) \d\d, 20\d\d \d{1,2}:\d\d:\d\d(am|pm))</div>' \
-o -r '$1' -I -N -- "$@" > "$tmp"
python3 -c '
import sys
try:
import plotly.express as px
import pandas as pd
except ModuleNotFoundError:
print("please install plotly and pandas: pip3 install plotly pandas",
file=sys.stderr)
sys.exit(1)
df = pd.read_csv(sys.argv[1], sep="\t", names=["timestamp"], parse_dates=[0],
infer_datetime_format=True)
px.histogram(df, x="timestamp").show()
for line in sys.stdin:
n = int(line.strip())
px.histogram(df, x="timestamp", nbins=n).show()
' "$tmp"