about summary refs log tree commit diff stats
path: root/app/assets/javascripts/ckeditor/plugins/lineutils
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-07-02 15:00:52 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-07-02 15:00:52 -0400
commit7971d7ac77c83717afcceaa1f476d1eb9afd5918 (patch)
tree5253143e7725b3f870d2f7070cf7b767c80ae1e7 /app/assets/javascripts/ckeditor/plugins/lineutils
parent1c606f4a6e99576614f5ce3c698f56e96d03e6a3 (diff)
downloadthoughts-7971d7ac77c83717afcceaa1f476d1eb9afd5918.tar.gz
thoughts-7971d7ac77c83717afcceaa1f476d1eb9afd5918.tar.bz2
thoughts-7971d7ac77c83717afcceaa1f476d1eb9afd5918.zip
Styled password reset form
Diffstat (limited to 'app/assets/javascripts/ckeditor/plugins/lineutils')
0 files changed, 0 insertions, 0 deletions
henberger <fefferburbia@gmail.com> 2017-01-09 14:01:51 -0500 committer Kelly Rauchenberger <fefferburbia@gmail.com> 2017-01-09 14:01:51 -0500 Initial commit' href='/cadence/commit/cadence.cpp?id=46b7119fab32b05923dbf9cda7cd6ce62f572846'>46b7119
af49d34 ^


46b7119



0e63553 ^
46b7119
0e63553 ^
af49d34 ^



0e63553 ^
af49d34 ^

46b7119
af49d34 ^
46b7119










0e63553 ^
46b7119



0e63553 ^
46b7119

















0e63553 ^
46b7119

0e63553 ^
46b7119











0e63553 ^
46b7119







af49d34 ^
46b7119



0e63553 ^
af49d34 ^
46b7119


0e63553 ^
46b7119

0e63553 ^
46b7119




0e63553 ^
46b7119






0e63553 ^
46b7119
0e63553 ^
46b7119





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











                          

                            












                                                                                                            
 





                                                                      
 
                               
 







                                                            
 








                                 
 
















                                              
 
                                             


                                                  



                                                    
 
                                                                                                   
 



                                                                                       
 

                                                              
 
                                                               










                                                                             
 



                                                                                                     
 

















                                                                     
 

                 
 











                                                                                                                              
 







                                                                                                            
                                                                          



                                          
 
                                                                                 


                             
 

                                                                     
 




                                    
 






                                                                
 
                                                         
 





                                                                    
#include <stdexcept>
#include <vector>
#include <string>
#include <yaml-cpp/yaml.h>
#include <sqlite3.h>
#include <iostream>
#include <fstream>
#include <twitter.h>
#include <chrono>
#include <thread>
#include <random>
#include <list>
#include <hkutil/string.h>
#include <hkutil/database.h>

const std::vector<std::string> moods = {"party", "chill", "crazy", "happy", "sad", "instrumental", "vocal"};

int main(int argc, char** argv)
{
  if (argc != 2)
  {
    std::cout << "usage: cadence [configfile]" << std::endl;
    return -1;
  }

  std::string configfile(argv[1]);
  YAML::Node config = YAML::LoadFile(configfile);

  // Set up the Twitter client.
  twitter::auth auth;
  auth.setConsumerKey(config["consumer_key"].as<std::string>());
  auth.setConsumerSecret(config["consumer_secret"].as<std::string>());
  auth.setAccessKey(config["access_key"].as<std::string>());
  auth.setAccessSecret(config["access_secret"].as<std::string>());

  twitter::client client(auth);

  // Read in the forms file.
  std::map<std::string, std::vector<std::string>> groups;
  std::ifstream datafile(config["forms"].as<std::string>());
  if (!datafile.is_open())
  {
    std::cout << "Could not find forms file." << std::endl;
    return 1;
  }

  bool newgroup = true;
  std::string line;
  std::string curgroup;
  while (getline(datafile, line))
  {
    if (line.back() == '\r')
    {
      line.pop_back();
    }

    if (newgroup)
    {
      curgroup = line;
      newgroup = false;
    } else {
      if (line.empty())
      {
        newgroup = true;
      } else {
        groups[curgroup].push_back(line);
      }
    }
  }

  // Initialize the random number generator.
  std::random_device random_device;
  std::mt19937 random_engine{random_device()};

  // Connect to the AcousticBrainz data file.
  hatkirby::database abdb(
    config["acoustic_datafile"].as<std::string>(),
    hatkirby::dbmode::read);

  for (;;)
  {
    std::cout << "Generating tweet..." << std::endl;

    std::string mood = moods[std::uniform_int_distribution<int>(0, moods.size()-1)(random_engine)];

    hatkirby::row song =
      abdb.queryFirst(
        "SELECT title, artist FROM songs WHERE category = ? ORDER BY RANDOM() LIMIT 1",
        { mood });

    std::string songTitle = mpark::get<std::string>(song[0]);
    std::string songArtist = mpark::get<std::string>(song[1]);

    std::string action = "{" + hatkirby::uppercase(mood) + "}";
    int tknloc;
    while ((tknloc = action.find("{")) != std::string::npos)
    {
      std::string token = action.substr(tknloc+1, action.find("}")-tknloc-1);
      std::string modifier;
      int modloc;
      if ((modloc = token.find(":")) != std::string::npos)
      {
        modifier = token.substr(modloc+1);
        token = token.substr(0, modloc);
      }

      std::string canontkn;
      std::transform(std::begin(token), std::end(token), std::back_inserter(canontkn), [] (char ch) {
        return std::toupper(ch);
      });

      std::string result;
      if (canontkn == "\\N")
      {
        result = "\n";
      } else if (canontkn == "ARTIST")
      {
        result = songArtist;
      } else if (canontkn == "SONG")
      {
        result = "\"" + songTitle + "\"";
      } else if (groups.count(canontkn)) {
        auto& group = groups.at(canontkn);
        std::uniform_int_distribution<int> dist(0, group.size() - 1);

        result = group[dist(random_engine)];
      } else {
        std::cout << "Badly formatted forms file:" << std::endl;
        std::cout << "No such form as " + canontkn << std::endl;

        return 1;
      }

      if (modifier == "indefinite")
      {
        if ((result.length() > 1) && (isupper(result[0])) && (isupper(result[1])))
        {
          result = "an " + result;
        } else if ((result[0] == 'a') || (result[0] == 'e') || (result[0] == 'i') || (result[0] == 'o') || (result[0] == 'u'))
        {
          result = "an " + result;
        } else {
          result = "a " + result;
        }
      }

      std::string finalresult;
      if (islower(token[0]))
      {
        std::transform(std::begin(result), std::end(result), std::back_inserter(finalresult), [] (char ch) {
          return std::tolower(ch);
        });
      } else if (isupper(token[0]) && !isupper(token[1]))
      {
        auto words = hatkirby::split<std::list<std::string>>(result, " ");
        for (auto& word : words)
        {
          word[0] = std::toupper(word[0]);
        }

        finalresult = hatkirby::implode(std::begin(words), std::end(words), " ");
      } else {
        finalresult = result;
      }

      action.replace(tknloc, action.find("}")-tknloc+1, finalresult);
    }

    if (action.size() <= 140)
    {
      try
      {
        client.updateStatus(action);

        std::cout << action << std::endl;
      } catch (const twitter::twitter_error& e)
      {
        std::cout << "Twitter error: " << e.what() << std::endl;
      }

      std::cout << "Waiting..." << std::endl;

      std::this_thread::sleep_for(std::chrono::hours(1));

      std::cout << std::endl;
    } else {
      std::cout << "Tweet was too long, regenerating." << std::endl;
    }
  }
}