Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <string>
- #include <fstream>
- #include <sstream>
- #include <thread>
- #include <chrono>
- #include "notify_time.h"
- #include "event.h"
- void load_conf(std::vector<event_t>& events, const std::string& path)
- {
- std::ifstream times(path);
- std::string line;
- while (std::getline(times, line))
- {
- std::istringstream stream(line);
- std::vector<std::string> event;
- std::string str;
- while (stream >> str)
- event.push_back(str);
- events.push_back(event);
- }
- times.close();
- }
- void event_loop(const std::vector<event_t>& events, const bool loop)
- {
- do
- {
- std::string weekday = current_weekday();
- const unsigned daily_time = current_time();
- for (const event_t& event : events)
- {
- if (event.day() == weekday)
- {
- if (loop)
- {
- if (daily_time == event.time(time_constant::warn_time))
- send_notif(event, time_constant::warn_notif);
- else if (daily_time == event.time(time_constant::start_time))
- send_notif(event, time_constant::start_notif);
- else if (daily_time == event.time(time_constant::end_time))
- send_notif(event, time_constant::end_notif);
- }
- else
- {
- if (daily_time >= event.time(time_constant::warn_time) && daily_time < event.time(time_constant::start_time))
- send_notif(event, time_constant::about_to_start_notif);
- else if (daily_time >= event.time(time_constant::start_time) && daily_time < event.time(time_constant::end_time))
- send_notif(event, time_constant::in_progress_notif);
- }
- }
- }
- pause(1000);
- }
- while (loop);
- }
- const unsigned current_time()
- {
- std::time_t t = std::time(NULL);
- struct tm *now = std::localtime(&t);
- return now->tm_hour * 3600 + now->tm_min * 60 + now->tm_sec;
- }
- const std::string current_weekday()
- {
- std::time_t t = std::time(NULL);
- struct tm *now = std::localtime(&t);
- return time_constant::days[now->tm_wday];
- }
- void pause(const unsigned milli)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(milli));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement