Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import httpclient, math, tables, strutils, queues, sequtils, os
- randomize(100) # To know for sure
- var wordTable = initTable[int, string]()
- var wordCount = 0
- for line in "/usr/share/dict/words".lines:
- wordTable[wordCount] = line
- wordCount = wordCount + 1
- proc getRandomString(wordTable: Table[int,string], countOfWordsInTable: int) : tuple[comment:string,tags:string] =
- var words = initQueue[string]()
- var tags = initQueue[string]()
- var numberOfWords = random(10) + 3
- for i in (0..numberOfWords-1):
- var r = random(countOfWordsInTable)
- var word = wordTable[r]
- words.add(word)
- if i < 3:
- tags.add("\"$1\"" % word)
- var c = join(toSeq(words.items), " ")
- var t = join(toSeq(tags.items),",")
- (c, t)
- proc getPostBody(comment:string, sentiment:string, date:string, tags: string): string=
- """{ "comment" : "$1", "sentiment": "$2", "date": "$3", "tag": [$4] }""" % [comment, sentiment, date, tags]
- proc upload(body:string): string=
- try:
- postContent(url="http://localhost:9200/feedback/comment/", body=body)
- except:
- echo "ERROR CAUSED"
- echo body
- sleep(5000)
- postContent("http://localhost:9200/feedback/comment/", body=body)
- proc getSentiment(month:string):string=
- var r = random(10)
- var dividor = 7
- if month == "01" or month == "06":
- dividor = 3
- if r < dividor:
- "neg"
- else:
- "pos"
- proc getDate(): tuple[day: string, month: string, year: string]=
- var id = random(28) + 1
- var idf = if id < 10: "0$1" else: "$1"
- var d = format (idf, id)
- var im = random(12) + 1
- var imf = if im < 10: "0$1" else: "$1"
- var m = format(imf,im)
- var y = "2014"
- (d, m, y)
- for i in (1..20000):
- var (d,m,y)=getDate()
- var date="$1/$2/$3" % [y,m,d]
- var sentiment=getSentiment(m)
- var (comment,tags) = getRandomString(wordTable, wordCount)
- var body=getPostBody(comment, sentiment, date, tags)
- var result=upload(body)
- echo body
- echo result
- echo "--------"
Advertisement
Add Comment
Please, Sign In to add comment