summary refs log tree commit diff stats
path: root/registry/index.go
diff options
context:
space:
mode:
Diffstat (limited to 'registry/index.go')
-rw-r--r--registry/index.go117
1 files changed, 117 insertions, 0 deletions
diff --git a/registry/index.go b/registry/index.go
new file mode 100644
index 0000000..85277fc
--- /dev/null
+++ b/registry/index.go
@@ -0,0 +1,117 @@
+package registry
+
+import (
+	"log"
+	"sort"
+	"strings"
+	"time"
+)
+
+// NewUserIndex returns a new instance of a user index
+func NewUserIndex() *UserIndex {
+	return &UserIndex{}
+}
+
+// AddUser inserts a new user into the index. The *Data struct
+// contains the nickname and the time the user was added.
+func (index UserIndex) AddUser(nick string, url string) {
+	rfc3339date, err := time.Now().MarshalText()
+	if err != nil {
+		log.Printf("Error formatting user add time as RFC3339: %v\n", err)
+	}
+	imutex.Lock()
+	index[url] = &Data{nick: nick, date: time.Now(), apidate: rfc3339date}
+	imutex.Unlock()
+}
+
+// DelUser removes a user from the index completely.
+func (index UserIndex) DelUser(url string) {
+	imutex.Lock()
+	delete(index, url)
+	imutex.Unlock()
+}
+
+// QueryUser checks the user index for nicknames that contain the
+// nickname provided as an argument. Entries are returned sorted
+// by the date they were added to the index.
+func (index UserIndex) QueryUser(name string) []string {
+	var timekey = map[time.Time]string{}
+	var sortedkeys TimeSlice
+	var users []string
+	imutex.RLock()
+	for k, v := range index {
+		if strings.Contains(v.nick, name) {
+			timekey[v.date] = v.nick + "\t" + k + "\t" + string(v.apidate)
+			sortedkeys = append(sortedkeys, v.date)
+		}
+	}
+	imutex.RUnlock()
+	sort.Sort(sortedkeys)
+	for _, e := range sortedkeys {
+		users = append(users, timekey[e])
+	}
+
+	return users
+}
+
+// QueryTag returns all the known statuses that
+// contain the provided tag.
+func (index UserIndex) QueryTag(tag string) []string {
+	var statusmap StatusMapSlice
+	i := 0
+	imutex.RLock()
+	for _, v := range index {
+		statusmap[i] = v.FindTag(tag)
+		i++
+	}
+	imutex.RUnlock()
+
+	return statusmap.SortByTime()
+}
+
+// FindTag takes a user's tweets and looks for a given tag.
+// Returns the tweets with the tag as a []string.
+func (userdata *Data) FindTag(tag string) StatusMap {
+	var statuses StatusMap
+	for k, e := range userdata.status {
+		parts := strings.Split(e, "\t")
+		statusslice := strings.Split(parts[3], " ")
+		for _, v := range statusslice {
+			if v[1:] == tag {
+				statuses[k] = e
+				break
+			}
+		}
+	}
+
+	return statuses
+}
+
+// SortByTime returns a string slice of the statuses sorted by time
+func (sm StatusMapSlice) SortByTime() []string {
+	var tagmap StatusMap
+	var times TimeSlice
+	var statuses []string
+	for _, e := range sm {
+		for k, v := range e {
+			tagmap[k] = v
+		}
+	}
+	for k := range tagmap {
+		times = append(times, k)
+	}
+	sort.Sort(times)
+	for _, e := range times {
+		statuses = append(statuses, tagmap[e])
+	}
+
+	return statuses
+}
+
+// GetStatuses returns the string slice containing a user's statuses
+func (index UserIndex) GetStatuses(url string) StatusMap {
+	imutex.RLock()
+	status := index[url].status
+	imutex.RUnlock()
+	return status
+}
ranger/commit/doc/pydoc/ranger.fsobject.fsobject.html?h=v1.7.0&id=34a60763e79546e0f84e30fbcc430632f3dbb39e'>34a60763 ^
f07bb12f ^




a614f048 ^

f07bb12f ^
























62cd83ba ^
c776804d ^

62cd83ba ^


f07bb12f ^


























34a60763 ^



f07bb12f ^
























































34a60763 ^
f07bb12f ^





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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200