notifier
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|ARM">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>ARM</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|ARM">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>ARM</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|ARM64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|ARM64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>ARM64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x86">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x86</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x86">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x86</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{3ecf1ab2-fbd0-43c8-beb9-11ff8bb66aa2}</ProjectGuid>
|
||||
<Keyword>Linux</Keyword>
|
||||
<RootNamespace>Eventnotifier_v2</RootNamespace>
|
||||
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
|
||||
<ApplicationType>Linux</ApplicationType>
|
||||
<ApplicationTypeRevision>1.0</ApplicationTypeRevision>
|
||||
<TargetLinuxPlatform>Generic</TargetLinuxPlatform>
|
||||
<LinuxProjectType>{D51BCBC9-82E9-4017-911E-C93873C4EA2B}</LinuxProjectType>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<RemoteRootDir>/home/sourcemodextensionstest</RemoteRootDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings" />
|
||||
<ImportGroup Label="Shared" />
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IncludePath>/home/sourcemodextensionstest/EventNotifier/boost_1_69_0;/home/sourcemodextensionstest/EventNotifier/includes/mysql;/home/sourcemodextensionstest/EventNotifier/includes/jdbc;/home/sourcemodextensionstest/EventNotifier/curl-7.62.0/include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>/home/sourcemodextensionstest/EventNotifier/boost_1_69_0/libs;/home/sourcemodextensionstest/EventNotifier/curl-7.62.0/lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
</ItemGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>/home/sourcemodextensionstest/EventNotifier/boost_1_69_0;/home/sourcemodextensionstest/EventNotifier/includes/jdbc;/home/sourcemodextensionstest/EventNotifier/includes/mysql;/home/sourcemodextensionstest/EventNotifier/curl-7.62.0/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>-lmysqlcppconn;-lcurl;$(StlAdditionalDependencies);%(Link.AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<RemoteTarget>-1386263875;104.248.40.216 (username=, port=22, authentication=Password)</RemoteTarget>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,286 @@
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
#include <cstdio>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <cppconn/driver.h>
|
||||
#include <cppconn/exception.h>
|
||||
#include <cppconn/resultset.h>
|
||||
#include <cppconn/statement.h>
|
||||
#include "mysql_connection.h"
|
||||
#include "mysql_driver.h"
|
||||
#include <curl/curl.h>
|
||||
/*
|
||||
g++ -v -x c -E -
|
||||
-lmysqlcppconn
|
||||
https://stackoverflow.com/questions/34057798/how-does-one-set-up-the-visual-studio-code-compiler-debugger-to-gcc
|
||||
https://docs.microsoft.com/en-us/cpp/linux/deploy-run-and-debug-your-linux-project?view=vs-2017
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
string data;
|
||||
string mapnames[10];
|
||||
string EventContent[5];
|
||||
string pattern[10];
|
||||
int SelectMysqlEventCount(sql::Connection *con)
|
||||
{
|
||||
sql::Statement *stmt;
|
||||
sql::ResultSet *res;
|
||||
int EventCount = 0;
|
||||
try {
|
||||
stmt = con->createStatement();
|
||||
res = stmt->executeQuery("SELECT * FROM `EventCount`");
|
||||
if (res->next()) {
|
||||
cout << res->getInt(1) << endl;
|
||||
EventCount = res->getInt(1);
|
||||
}
|
||||
}
|
||||
catch (sql::SQLException &e) {
|
||||
cout << "# ERR: SQLException in " << __FILE__;
|
||||
cout << "# ERR: " << e.what();
|
||||
cout << " (MySQL error code: " << e.getErrorCode();
|
||||
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
|
||||
}
|
||||
delete stmt;
|
||||
delete res;
|
||||
//cout << endl;
|
||||
return EventCount;
|
||||
}
|
||||
|
||||
size_t writeCallback(char* buf, size_t size, size_t nmemb, void* up)
|
||||
{
|
||||
for (std::size_t c = 0; c < size*nmemb; c++)
|
||||
{
|
||||
data.push_back(buf[c]);
|
||||
}
|
||||
return size * nmemb; //tell curl how many bytes we handled
|
||||
}
|
||||
|
||||
|
||||
string printreturn(std::string::size_type urlstringend, std::string const &s)
|
||||
{
|
||||
string strreturn("");
|
||||
if (urlstringend == std::string::npos) {
|
||||
strreturn = "not found sdbhabd2342d";
|
||||
}
|
||||
else
|
||||
{
|
||||
strreturn = s.substr(0, urlstringend);
|
||||
}
|
||||
return strreturn;
|
||||
}
|
||||
|
||||
void removeSubstrs(string& s, string& p) {
|
||||
string::size_type n = p.length();
|
||||
for (string::size_type i = s.find(p);
|
||||
i != string::npos;
|
||||
i = s.find(p))
|
||||
s.erase(i, n);
|
||||
}
|
||||
|
||||
void ReadForumSubSectionEvent()
|
||||
{
|
||||
int index;
|
||||
CURL* curl;
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
curl_easy_setopt(curl, CURLOPT_URL, "https://unloze.com/forums/events.76/");
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
|
||||
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); //tell curl to output its progress
|
||||
curl_easy_perform(curl);
|
||||
//check by taking the first from the top of the page, thats always the newest in order
|
||||
//the needed context is always close, instead of taking the full size we only take the needed portion distance
|
||||
std::string::size_type urlstringend;
|
||||
urlstringend = data.find("preview\">Event #");
|
||||
std::string sdeli = ("data-previewUrl=\"");
|
||||
string strf = printreturn(urlstringend, data);
|
||||
size_t pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos) {
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
}
|
||||
data.clear();
|
||||
strf.insert(0, "https://unloze.com/");
|
||||
//https://unloze.com/threads/event-54n74-15-b4ck.1324 is returned here for example
|
||||
std::cout << "strf.c_str(): " << strf.c_str() << "\n";
|
||||
curl_easy_setopt(curl, CURLOPT_URL, strf.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
|
||||
curl_easy_perform(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
curl_global_cleanup();
|
||||
//assumes only ze event threads contain "CS:S Zombie Escape"
|
||||
//mapnames collects maps specified to event
|
||||
urlstringend = data.find("CS:S Zombie Escape");
|
||||
strf = printreturn(urlstringend, data);
|
||||
if (strf.find("not found sdbhabd2342d") == std::string::npos)
|
||||
{
|
||||
urlstringend = data.find("Prize :");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("<a href=\"http://fastdl.unloze.com/css_ze/maps/");
|
||||
pos = 0;
|
||||
while ((pos = strf.find(sdeli)) != std::string::npos && index < 10)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
mapnames[index] = strf.substr(0, strf.find(".bsp.bz2"));
|
||||
std::cout << "mapnames[index]: " << mapnames[index] << "\n";
|
||||
index++;
|
||||
}
|
||||
//EventContent 0 = title
|
||||
urlstringend = data.find("| UNLOZE</title>");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("<title>");
|
||||
pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
EventContent[0] = strf;
|
||||
}
|
||||
//EventContent 1 = rewards
|
||||
urlstringend = data.find("<div class=\"messageTextEndMarker\"> </div>");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("Prize :");
|
||||
pos = 0;
|
||||
index = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
size_t index1 = 0;
|
||||
pattern[0] = "</span>";
|
||||
pattern[1] = "<br/>";
|
||||
pattern[2] = "<b>";
|
||||
pattern[3] = "</b>";
|
||||
string teststr = strf;
|
||||
while (!!pattern[index].size())
|
||||
{
|
||||
removeSubstrs(teststr, pattern[index]);
|
||||
index++;
|
||||
}
|
||||
//std::cout << "teststr: " << "\n" << teststr << "\n";
|
||||
strf = teststr;
|
||||
EventContent[1] = strf;
|
||||
}
|
||||
//EventContent 2 = leader
|
||||
urlstringend = data.find("Prize :");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("Leader :</span>");
|
||||
pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
//std::cout << "reached eventcontent2 strf: " << strf << "\n";
|
||||
EventContent[2] = strf.substr(0, strf.find("<"));
|
||||
}
|
||||
//EventContent 3 = date
|
||||
urlstringend = data.find("\">Time :");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("Date :</span>");
|
||||
pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
EventContent[3] = strf.substr(0, strf.find("<"));
|
||||
}
|
||||
//EventContent[4] = hours
|
||||
urlstringend = data.find("Leader :");
|
||||
strf = printreturn(urlstringend, data);
|
||||
sdeli = ("Time :</span>");
|
||||
pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
strf = strf.substr(0, strf.find("pm GMT+1"));
|
||||
}
|
||||
sdeli = ("//");
|
||||
pos = 0;
|
||||
if ((pos = strf.find(sdeli)) != std::string::npos)
|
||||
{
|
||||
strf.erase(0, pos + sdeli.length());
|
||||
EventContent[4] = strf;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Not found" << "\n" << "data value: " << data << "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MYSQLUpdateEventMaps(sql::Connection *con)
|
||||
{
|
||||
sql::Statement *stmt;
|
||||
try {
|
||||
stmt = con->createStatement();
|
||||
stmt->executeUpdate("delete from Maps");
|
||||
int index;
|
||||
while (!!mapnames[index].size())
|
||||
{
|
||||
stmt->executeUpdate("INSERT INTO `Maps` (`MapNames`) VALUES (\"" + mapnames[index] + "\")");
|
||||
index++;
|
||||
}
|
||||
}
|
||||
catch (sql::SQLException &e) {
|
||||
cout << "# ERR: SQLException in " << __FILE__;
|
||||
cout << "# ERR: " << e.what();
|
||||
cout << " (MySQL error code: " << e.getErrorCode();
|
||||
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
|
||||
}
|
||||
delete stmt;
|
||||
}
|
||||
|
||||
void MYSQLUpdateEventContent(sql::Connection *con)
|
||||
{
|
||||
sql::Statement *stmt;
|
||||
try {
|
||||
stmt = con->createStatement();
|
||||
stmt->executeUpdate("UPDATE `EventContent` SET `title`=\"" + EventContent[0] +"\",`Rewards`=\"" + EventContent[1]
|
||||
+ "\",`Leaders`=\"" + EventContent[2] + "\",`datum`=\"" + EventContent[3] + "\",`hours`=\"" + EventContent[4] + "\"");
|
||||
}catch (sql::SQLException &e) {
|
||||
cout << "# ERR: SQLException in " << __FILE__;
|
||||
cout << "# ERR: " << e.what();
|
||||
cout << " (MySQL error code: " << e.getErrorCode();
|
||||
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
|
||||
}
|
||||
delete stmt;
|
||||
}
|
||||
|
||||
bool CloseDBConnection(sql::Connection *con)
|
||||
{
|
||||
try
|
||||
{
|
||||
con->close();
|
||||
delete con;
|
||||
return true;
|
||||
}
|
||||
catch (sql::SQLException &e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
sql::mysql::MySQL_Driver *driver;
|
||||
sql::Connection *con;
|
||||
driver = sql::mysql::get_driver_instance();
|
||||
con = driver->connect("tcp://151.80.230.149:3306", "eventscss", "sdbhb2h34b2hbhbdfwbfwhber234");
|
||||
con->setSchema("eventscss");
|
||||
try {
|
||||
//Eventcount = SelectMysqlEventCount(con);
|
||||
ReadForumSubSectionEvent();
|
||||
MYSQLUpdateEventMaps(con);
|
||||
MYSQLUpdateEventContent(con);
|
||||
CloseDBConnection(con);
|
||||
}
|
||||
catch (sql::SQLException &e) {
|
||||
cout << "# ERR: SQLException in " << __FILE__;
|
||||
cout << "# ERR: " << e.what();
|
||||
cout << " (MySQL error code: " << e.getErrorCode();
|
||||
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
|
||||
}
|
||||
cout << "EventContent[0]: " << EventContent[0] << endl;
|
||||
cout << "EventContent[1]: " << EventContent[1] << endl;
|
||||
cout << "EventContent[2]: " << EventContent[2] << endl;
|
||||
cout << "EventContent[3]: " << EventContent[3] << endl;
|
||||
cout << "EventContent[4]: " << EventContent[4] << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user