bot_twitter_ebooks 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,104 @@
1
+ # encoding: utf-8
2
+
3
+ module Ebooks
4
+ # This generator uses data similar to a Markov model, but
5
+ # instead of making a chain by looking up bigrams it uses the
6
+ # positions to randomly replace token array suffixes in one sentence
7
+ # with matching suffixes in another
8
+ class SuffixGenerator
9
+ # Build a generator from a corpus of tikified sentences
10
+ # "tikis" are token indexes-- a way of representing words
11
+ # and punctuation as their integer position in a big array
12
+ # of such tokens
13
+ # @param sentences [Array<Array<Integer>>]
14
+ # @return [SuffixGenerator]
15
+ def self.build(sentences)
16
+ SuffixGenerator.new(sentences)
17
+ end
18
+
19
+ def initialize(sentences)
20
+ @sentences = sentences.reject { |s| s.empty? }
21
+ @unigrams = {}
22
+ @bigrams = {}
23
+
24
+ @sentences.each_with_index do |tikis, i|
25
+ if (i % 10000 == 0) then
26
+ log ("Building: sentence #{i} of #{sentences.length}")
27
+ end
28
+ last_tiki = INTERIM
29
+ tikis.each_with_index do |tiki, j|
30
+ @unigrams[last_tiki] ||= []
31
+ @unigrams[last_tiki] << [i, j]
32
+
33
+ @bigrams[last_tiki] ||= {}
34
+ @bigrams[last_tiki][tiki] ||= []
35
+
36
+ if j == tikis.length-1 # Mark sentence endings
37
+ @unigrams[tiki] ||= []
38
+ @unigrams[tiki] << [i, INTERIM]
39
+ @bigrams[last_tiki][tiki] << [i, INTERIM]
40
+ else
41
+ @bigrams[last_tiki][tiki] << [i, j+1]
42
+ end
43
+
44
+ last_tiki = tiki
45
+ end
46
+ end
47
+
48
+ self
49
+ end
50
+
51
+ # Generate a recombined sequence of tikis
52
+ # @param passes [Integer] number of times to recombine
53
+ # @param n [Symbol] :unigrams or :bigrams (affects how conservative the model is)
54
+ # @return [Array<Integer>]
55
+ def generate(passes=5, n=:unigrams)
56
+ index = rand(@sentences.length)
57
+ tikis = @sentences[index]
58
+ used = [index] # Sentences we've already used
59
+ verbatim = [tikis] # Verbatim sentences to avoid reproducing
60
+
61
+ 0.upto(passes-1) do
62
+ varsites = {} # Map bigram start site => next tiki alternatives
63
+
64
+ tikis.each_with_index do |tiki, i|
65
+ next_tiki = tikis[i+1]
66
+ break if next_tiki.nil?
67
+
68
+ alternatives = (n == :unigrams) ? @unigrams[next_tiki] : @bigrams[tiki][next_tiki]
69
+ # Filter out suffixes from previous sentences
70
+ alternatives.reject! { |a| a[1] == INTERIM || used.include?(a[0]) }
71
+ varsites[i] = alternatives unless alternatives.empty?
72
+ end
73
+
74
+ variant = nil
75
+ varsites.to_a.shuffle.each do |site|
76
+ start = site[0]
77
+
78
+ site[1].shuffle.each do |alt|
79
+ verbatim << @sentences[alt[0]]
80
+ suffix = @sentences[alt[0]][alt[1]..-1]
81
+ potential = tikis[0..start+1] + suffix
82
+
83
+ # Ensure we're not just rebuilding some segment of another sentence
84
+ unless verbatim.find { |v| NLP.subseq?(v, potential) || NLP.subseq?(potential, v) }
85
+ used << alt[0]
86
+ variant = potential
87
+ break
88
+ end
89
+ end
90
+
91
+ break if variant
92
+ end
93
+
94
+ # If we failed to produce a variation from any alternative, there
95
+ # is no use running additional passes-- they'll have the same result.
96
+ break if variant.nil?
97
+
98
+ tikis = variant
99
+ end
100
+
101
+ tikis
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'twitter'
5
+ require 'json'
6
+ require 'mini_magick'
7
+ require 'open-uri'
8
+ require 'pry'
9
+
10
+ module Ebooks
11
+ class Sync
12
+
13
+ def self.run(botname, username)
14
+ bot = Ebooks::Bot.get(botname)
15
+ bot.configure
16
+ source_user = username
17
+ ebooks_user = bot.username
18
+ user = bot.twitter.user(source_user)
19
+ if user.profile_image_url then
20
+ Ebooks::Sync::get(user.profile_image_url(:original), "image/#{source_user}_avatar")
21
+ avatar = MiniMagick::Image.open("image/#{source_user}_avatar")
22
+ avatar.flip
23
+ avatar.write("image/#{ebooks_user}_avatar")
24
+ avatar64 = Base64.encode64(File.read("image/#{ebooks_user}_avatar"))
25
+ bot.twitter.update_profile_image(avatar64)
26
+ p "Updated profile image for #{ebooks_user} from #{source_user}."
27
+ else
28
+ p "#{source_user} does not have a profile image to clone."
29
+ end
30
+ if user.profile_banner_url then
31
+ Ebooks::Sync::get(user.profile_banner_url, "image/#{source_user}banner")
32
+ banner = MiniMagick::Image.open("image/#{source_user}banner")
33
+ banner.flip
34
+ banner.write("image/#{ebooks_user}_banner")
35
+ banner64 = Base64.encode64(File.read("image/#{ebooks_user}_banner"))
36
+ bot.twitter.update_profile_banner(banner64)
37
+ p "Updated cover image for #{ebooks_user} from #{source_user}."
38
+ else
39
+ p "#{source_user} does not have a cover image to clone."
40
+ end
41
+ end
42
+
43
+ def self.get(url, destination)
44
+ File.open(destination, "wb") do |saved_file|
45
+ open(url, "rb") do |read_file|
46
+ saved_file.write(read_file.read)
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Ebooks
2
+ VERSION = "0.0.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+ ruby '{{RUBY_VERSION}}'
3
+
4
+ gem 'bot_twitter_ebooks'
@@ -0,0 +1 @@
1
+ worker: bundle exec ebooks start
@@ -0,0 +1,66 @@
1
+ require 'bot_twitter_ebooks'
2
+
3
+ # This is an example bot definition with event handlers commented out
4
+ # You can define and instantiate as many bots as you like
5
+
6
+ class MyBot < Ebooks::Bot
7
+ # Configuration here applies to all MyBots
8
+ def configure
9
+ # Consumer details come from registering an app at https://dev.twitter.com/
10
+ # Once you have consumer details, use "ebooks auth" for new access tokens
11
+ self.consumer_key = '' # Your app consumer key
12
+ self.consumer_secret = '' # Your app consumer secret
13
+
14
+ # Users to block instead of interacting with
15
+ self.blacklist = ['tnietzschequote']
16
+
17
+ # Range in seconds to randomize delay when bot.delay is called
18
+ self.delay_range = 1..6
19
+ end
20
+
21
+ def on_startup
22
+ scheduler.every '24h' do
23
+ # Tweet something every 24 hours
24
+ # See https://github.com/jmettraux/rufus-scheduler
25
+ # tweet("hi")
26
+ # pictweet("hi", "cuteselfie.jpg")
27
+ end
28
+ end
29
+
30
+ def on_message(dm)
31
+ # Reply to a DM
32
+ # Make sure to set your API permissions to "Read, Write and Access direct messages" or this won't work!
33
+ # reply(dm, "secret secrets")
34
+ end
35
+
36
+ def on_follow(user)
37
+ # Follow a user back
38
+ # follow(user.screen_name)
39
+ end
40
+
41
+ def on_mention(tweet)
42
+ # Reply to a mention
43
+ # reply(tweet, "oh hullo")
44
+ end
45
+
46
+ def on_timeline(tweet)
47
+ # Reply to a tweet in the bot's timeline
48
+ # reply(tweet, "nice tweet")
49
+ end
50
+
51
+ def on_favorite(user, tweet)
52
+ # Follow user who just favorited bot's tweet
53
+ # follow(user.screen_name)
54
+ end
55
+
56
+ def on_retweet(tweet)
57
+ # Follow user who just retweeted bot's tweet
58
+ # follow(tweet.user.screen_name)
59
+ end
60
+ end
61
+
62
+ # Make a MyBot and attach it to an account
63
+ MyBot.new("{{BOT_NAME}}") do |bot|
64
+ bot.access_token = "" # Token connecting the app to this account
65
+ bot.access_token_secret = "" # Secret connecting the app to this account
66
+ end
File without changes
@@ -0,0 +1 @@
1
+ corpus/
File without changes
File without changes
@@ -0,0 +1,843 @@
1
+ a
2
+ able
3
+ about
4
+ above
5
+ abst
6
+ accordance
7
+ according
8
+ accordingly
9
+ across
10
+ act
11
+ actually
12
+ added
13
+ adj
14
+ affected
15
+ affecting
16
+ affects
17
+ after
18
+ afterwards
19
+ again
20
+ against
21
+ ah
22
+ all
23
+ almost
24
+ alone
25
+ along
26
+ already
27
+ also
28
+ although
29
+ always
30
+ am
31
+ among
32
+ amongst
33
+ an
34
+ and
35
+ announce
36
+ another
37
+ any
38
+ anybody
39
+ anyhow
40
+ anymore
41
+ anyone
42
+ anything
43
+ anyway
44
+ anyways
45
+ anywhere
46
+ apparently
47
+ approximately
48
+ are
49
+ aren
50
+ arent
51
+ arise
52
+ around
53
+ as
54
+ aside
55
+ ask
56
+ asking
57
+ at
58
+ auth
59
+ available
60
+ away
61
+ awfully
62
+ b
63
+ back
64
+ be
65
+ became
66
+ because
67
+ become
68
+ becomes
69
+ becoming
70
+ been
71
+ before
72
+ beforehand
73
+ begin
74
+ beginning
75
+ beginnings
76
+ begins
77
+ behind
78
+ being
79
+ believe
80
+ below
81
+ beside
82
+ besides
83
+ between
84
+ beyond
85
+ biol
86
+ both
87
+ brief
88
+ briefly
89
+ but
90
+ by
91
+ c
92
+ ca
93
+ came
94
+ can
95
+ cannot
96
+ can't
97
+ cause
98
+ causes
99
+ certain
100
+ certainly
101
+ co
102
+ com
103
+ come
104
+ comes
105
+ contain
106
+ containing
107
+ contains
108
+ could
109
+ couldnt
110
+ d
111
+ date
112
+ did
113
+ didn't
114
+ different
115
+ do
116
+ does
117
+ doesn't
118
+ doing
119
+ done
120
+ don't
121
+ down
122
+ downwards
123
+ due
124
+ during
125
+ e
126
+ each
127
+ ed
128
+ edu
129
+ effect
130
+ eg
131
+ eight
132
+ eighty
133
+ either
134
+ else
135
+ elsewhere
136
+ end
137
+ ending
138
+ enough
139
+ especially
140
+ et
141
+ et-al
142
+ etc
143
+ even
144
+ ever
145
+ every
146
+ everybody
147
+ everyone
148
+ everything
149
+ everywhere
150
+ ex
151
+ except
152
+ f
153
+ far
154
+ few
155
+ ff
156
+ fifth
157
+ first
158
+ five
159
+ fix
160
+ followed
161
+ following
162
+ follows
163
+ for
164
+ former
165
+ formerly
166
+ forth
167
+ found
168
+ four
169
+ from
170
+ further
171
+ furthermore
172
+ g
173
+ gave
174
+ get
175
+ gets
176
+ getting
177
+ give
178
+ given
179
+ gives
180
+ giving
181
+ go
182
+ goes
183
+ gone
184
+ got
185
+ gotten
186
+ h
187
+ had
188
+ happens
189
+ hardly
190
+ has
191
+ hasn't
192
+ have
193
+ haven't
194
+ having
195
+ he
196
+ hed
197
+ hence
198
+ her
199
+ here
200
+ hereafter
201
+ hereby
202
+ herein
203
+ heres
204
+ hereupon
205
+ hers
206
+ herself
207
+ hes
208
+ hi
209
+ hid
210
+ him
211
+ himself
212
+ his
213
+ hither
214
+ home
215
+ how
216
+ howbeit
217
+ however
218
+ hundred
219
+ i
220
+ id
221
+ ie
222
+ if
223
+ i'll
224
+ im
225
+ immediate
226
+ immediately
227
+ importance
228
+ important
229
+ in
230
+ inc
231
+ indeed
232
+ index
233
+ information
234
+ instead
235
+ into
236
+ invention
237
+ inward
238
+ is
239
+ isn't
240
+ it
241
+ itd
242
+ it'll
243
+ its
244
+ itself
245
+ i've
246
+ j
247
+ just
248
+ k
249
+ keep
250
+ keeps
251
+ kept
252
+ kg
253
+ km
254
+ know
255
+ known
256
+ knows
257
+ l
258
+ largely
259
+ last
260
+ lately
261
+ later
262
+ latter
263
+ latterly
264
+ least
265
+ less
266
+ lest
267
+ let
268
+ lets
269
+ like
270
+ liked
271
+ likely
272
+ line
273
+ little
274
+ 'll
275
+ look
276
+ looking
277
+ looks
278
+ ltd
279
+ m
280
+ made
281
+ mainly
282
+ make
283
+ makes
284
+ many
285
+ may
286
+ maybe
287
+ me
288
+ mean
289
+ means
290
+ meantime
291
+ meanwhile
292
+ merely
293
+ mg
294
+ might
295
+ million
296
+ miss
297
+ ml
298
+ more
299
+ moreover
300
+ most
301
+ mostly
302
+ mr
303
+ mrs
304
+ much
305
+ mug
306
+ must
307
+ my
308
+ myself
309
+ n
310
+ na
311
+ name
312
+ namely
313
+ nay
314
+ nd
315
+ near
316
+ nearly
317
+ necessarily
318
+ necessary
319
+ need
320
+ needs
321
+ neither
322
+ never
323
+ nevertheless
324
+ new
325
+ next
326
+ nine
327
+ ninety
328
+ no
329
+ nobody
330
+ non
331
+ none
332
+ nonetheless
333
+ noone
334
+ nor
335
+ normally
336
+ nos
337
+ not
338
+ noted
339
+ nothing
340
+ now
341
+ nowhere
342
+ o
343
+ obtain
344
+ obtained
345
+ obviously
346
+ of
347
+ off
348
+ often
349
+ oh
350
+ ok
351
+ okay
352
+ old
353
+ omitted
354
+ on
355
+ once
356
+ one
357
+ ones
358
+ only
359
+ onto
360
+ or
361
+ ord
362
+ other
363
+ others
364
+ otherwise
365
+ ought
366
+ our
367
+ ours
368
+ ourselves
369
+ out
370
+ outside
371
+ over
372
+ overall
373
+ owing
374
+ own
375
+ p
376
+ page
377
+ pages
378
+ part
379
+ particular
380
+ particularly
381
+ past
382
+ per
383
+ perhaps
384
+ placed
385
+ please
386
+ plus
387
+ poorly
388
+ possible
389
+ possibly
390
+ potentially
391
+ pp
392
+ predominantly
393
+ present
394
+ previously
395
+ primarily
396
+ probably
397
+ promptly
398
+ proud
399
+ provides
400
+ put
401
+ q
402
+ que
403
+ quickly
404
+ quite
405
+ qv
406
+ r
407
+ ran
408
+ rather
409
+ rd
410
+ re
411
+ readily
412
+ really
413
+ recent
414
+ recently
415
+ ref
416
+ refs
417
+ regarding
418
+ regardless
419
+ regards
420
+ related
421
+ relatively
422
+ research
423
+ respectively
424
+ resulted
425
+ resulting
426
+ results
427
+ right
428
+ run
429
+ s
430
+ said
431
+ same
432
+ saw
433
+ say
434
+ saying
435
+ says
436
+ sec
437
+ section
438
+ see
439
+ seeing
440
+ seem
441
+ seemed
442
+ seeming
443
+ seems
444
+ seen
445
+ self
446
+ selves
447
+ sent
448
+ seven
449
+ several
450
+ shall
451
+ she
452
+ shed
453
+ she'll
454
+ shes
455
+ should
456
+ shouldn't
457
+ show
458
+ showed
459
+ shown
460
+ showns
461
+ shows
462
+ significant
463
+ significantly
464
+ similar
465
+ similarly
466
+ since
467
+ six
468
+ slightly
469
+ so
470
+ some
471
+ somebody
472
+ somehow
473
+ someone
474
+ somethan
475
+ something
476
+ sometime
477
+ sometimes
478
+ somewhat
479
+ somewhere
480
+ soon
481
+ sorry
482
+ specifically
483
+ specified
484
+ specify
485
+ specifying
486
+ still
487
+ stop
488
+ strongly
489
+ sub
490
+ substantially
491
+ successfully
492
+ such
493
+ sufficiently
494
+ suggest
495
+ sup
496
+ sure
497
+ t
498
+ take
499
+ taken
500
+ taking
501
+ tell
502
+ tends
503
+ th
504
+ than
505
+ thank
506
+ thanks
507
+ thanx
508
+ that
509
+ that'll
510
+ thats
511
+ that've
512
+ the
513
+ their
514
+ theirs
515
+ them
516
+ themselves
517
+ then
518
+ thence
519
+ there
520
+ thereafter
521
+ thereby
522
+ thered
523
+ therefore
524
+ therein
525
+ there'll
526
+ thereof
527
+ therere
528
+ theres
529
+ thereto
530
+ thereupon
531
+ there've
532
+ these
533
+ they
534
+ theyd
535
+ they'll
536
+ theyre
537
+ they've
538
+ think
539
+ this
540
+ those
541
+ thou
542
+ though
543
+ thoughh
544
+ thousand
545
+ throug
546
+ through
547
+ throughout
548
+ thru
549
+ thus
550
+ til
551
+ tip
552
+ to
553
+ together
554
+ too
555
+ took
556
+ toward
557
+ towards
558
+ tried
559
+ tries
560
+ truly
561
+ try
562
+ trying
563
+ ts
564
+ twice
565
+ two
566
+ u
567
+ un
568
+ under
569
+ unfortunately
570
+ unless
571
+ unlike
572
+ unlikely
573
+ until
574
+ unto
575
+ up
576
+ upon
577
+ ups
578
+ us
579
+ use
580
+ used
581
+ useful
582
+ usefully
583
+ usefulness
584
+ uses
585
+ using
586
+ usually
587
+ v
588
+ value
589
+ various
590
+ 've
591
+ very
592
+ via
593
+ viz
594
+ vol
595
+ vols
596
+ vs
597
+ w
598
+ want
599
+ wants
600
+ was
601
+ wasn't
602
+ way
603
+ we
604
+ wed
605
+ welcome
606
+ we'll
607
+ went
608
+ were
609
+ weren't
610
+ we've
611
+ what
612
+ whatever
613
+ what'll
614
+ whats
615
+ when
616
+ whence
617
+ whenever
618
+ where
619
+ whereafter
620
+ whereas
621
+ whereby
622
+ wherein
623
+ wheres
624
+ whereupon
625
+ wherever
626
+ whether
627
+ which
628
+ while
629
+ whim
630
+ whither
631
+ who
632
+ whod
633
+ whoever
634
+ whole
635
+ who'll
636
+ whom
637
+ whomever
638
+ whos
639
+ whose
640
+ why
641
+ widely
642
+ willing
643
+ wish
644
+ with
645
+ within
646
+ without
647
+ won't
648
+ words
649
+ world
650
+ would
651
+ wouldn't
652
+ www
653
+ x
654
+ y
655
+ yes
656
+ yet
657
+ you
658
+ youd
659
+ you'll
660
+ your
661
+ youre
662
+ yours
663
+ yourself
664
+ yourselves
665
+ you've
666
+ z
667
+ zero
668
+ .
669
+ ?
670
+ !
671
+
672
+ http
673
+ don
674
+ people
675
+ well
676
+ will
677
+ https
678
+ time
679
+ good
680
+ thing
681
+ twitter
682
+ pretty
683
+ it's
684
+ i'm
685
+ that's
686
+ you're
687
+ they're
688
+ there's
689
+ things
690
+ yeah
691
+ find
692
+ going
693
+ work
694
+ point
695
+ years
696
+ guess
697
+ bad
698
+ problem
699
+ real
700
+ kind
701
+ day
702
+ better
703
+ lot
704
+ stuff
705
+ i'd
706
+ read
707
+ thought
708
+ idea
709
+ case
710
+ word
711
+ hey
712
+ person
713
+ long
714
+ Dear
715
+ internet
716
+ tweet
717
+ he's
718
+ feel
719
+ wrong
720
+ call
721
+ hard
722
+ phone
723
+ ago
724
+ literally
725
+ remember
726
+ reason
727
+ called
728
+ course
729
+ bit
730
+ question
731
+ high
732
+ today
733
+ told
734
+ man
735
+ actual
736
+ year
737
+ three
738
+ book
739
+ assume
740
+ life
741
+ true
742
+ best
743
+ wow
744
+ video
745
+ times
746
+ works
747
+ fact
748
+ completely
749
+ totally
750
+ imo
751
+ open
752
+ lol
753
+ haha
754
+ cool
755
+ yep
756
+ ooh
757
+ great
758
+ ugh
759
+ tonight
760
+ talk
761
+ sounds
762
+ hahaha
763
+ whoa
764
+ cool
765
+ we're
766
+ guys
767
+ sweet
768
+ fortunately
769
+ hmm
770
+ aren't
771
+ sadly
772
+ talking
773
+ you'd
774
+ place
775
+ yup
776
+ what's
777
+ y'know
778
+ basically
779
+ god
780
+ shit
781
+ holy
782
+ interesting
783
+ news
784
+ guy
785
+ wait
786
+ oooh
787
+ gonna
788
+ current
789
+ let's
790
+ tomorrow
791
+ omg
792
+ hate
793
+ hope
794
+ fuck
795
+ oops
796
+ night
797
+ wear
798
+ wanna
799
+ fun
800
+ finally
801
+ whoops
802
+ nevermind
803
+ definitely
804
+ context
805
+ screen
806
+ free
807
+ exactly
808
+ big
809
+ house
810
+ half
811
+ working
812
+ play
813
+ heard
814
+ hmmm
815
+ damn
816
+ woah
817
+ tho
818
+ set
819
+ idk
820
+ sort
821
+ understand
822
+ kinda
823
+ seriously
824
+ btw
825
+ she's
826
+ hah
827
+ aww
828
+ ffs
829
+ it'd
830
+ that'd
831
+ hopefully
832
+ non
833
+ entirely
834
+ lots
835
+ entire
836
+ tend
837
+ hullo
838
+ clearly
839
+ surely
840
+ weird
841
+ start
842
+ help
843
+ nope