-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeup_checker.py
66 lines (55 loc) · 2.07 KB
/
writeup_checker.py
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
#-*- coding: utf-8 -*-
from writeup import WriteUp
import feedparser
class WriteUpChecker:
def __init__(self):
print "Wait data"
self.writeUpsList = self._getWriteUpsList()
print "All data has been received"
def _getWriteUpsList(self):
result = []
feed = feedparser.parse("https://ctftime.org/writeups/rss/")
print "Feed received"
print len(feed)
for writeup_entry in feed.entries:
result.append(WriteUp(writeup_entry))
print "List was collected"
return result
def getWriteUpsByTaskName(self, taskName):
result = []
for writeup in self.writeUpsList:
if writeup.task == taskName:
result.append(writeup)
return result
def getWriteUpsByGameName(self, gameName):
result = []
for writeup in self.writeUpsList:
if writeup.event == gameName:
result.append(writeup)
return result
def getWriteUpsByTags(self, tagsList, allTags=True):
result = []
for writeup in self.writeUpsList:
if allTags:
if self._isAllItemsAreEqual([(tag in writeup.tags) for tag in tagsList]):
result.append(writeup)
else:
if self._isAnyItemsAreEqual([(tag in writeup.tags) for tag in tagsList]):
result.append(writeup)
return result
def getWriteUpsByAuthor(self, author):
result = []
for writeup in self.writeUpsList:
if writeup.authorTeam == author:
result.append(writeup)
return result
def _isAllItemsAreEqual(self, collection):
return all(True == item for item in collection)
def _isAnyItemsAreEqual(self, collection):
return any(True == item for item in collection)
if __name__ == "__main__":
print "Start"
w = WriteUpChecker()
print len(w.getWriteUpsByTags(["reverse"]))
print len(w.getWriteUpsByTags(["binary", "exploitation"], False))
print len(w.getWriteUpsByTags(["crypto", "forensics"], False))