Commits

Fernando G N Rocha committed bc8be82

Iniciado repositório para organizar meus scripts e pequenos utilitários. Adicionado clock-osd, mostrar hora e bateria via notify-osd

Comments (0)

Files changed (2)

clock_osd/batt_monitor.py

+#!/usr/bin/python2
+# -*- coding: utf-8 -*-
+
+import re
+import os
+import time
+import procname
+
+procname.setprocname('batt_monitor')
+
+regex = re.compile('(\d+)%')
+icon = '/home/fernando/Downloads/imagens/battery_low2.png'
+while True:
+    acpi = os.popen('acpi').read()
+    percent = re.search(regex, acpi)
+    if int(percent.group(1)) <= 10 and not re.search('Charging', acpi):
+        delay = 30 
+        os.popen('notify-send -t 6000 -i ' + icon +  ' \'' + percent.group() + 
+        '  Baterria com nível muito baixo!\'')
+    else:
+        delay = 60
+    batt_stat = open('/home/fernando/.config/batt_statt', 'w')
+    batt_stat.write(percent.group() + ' ')
+    batt_stat.close()
+
+    time.sleep(delay)

clock_osd/clock-osd.c

+/* Compile: 
+ *
+ * gcc -O0 -ggdb -Wall -Werror `pkg-config --cflags --libs libnotify \
+ * glib-2.0` clock-osd.c -o clock
+ * */
+
+#include <stdio.h>
+#include <glib.h>
+#include <unistd.h>
+#include <libnotify/notify.h>
+#include <time.h>
+#include <string.h>
+#include <stdlib.h>
+
+char *batt();
+
+int 
+main (int    argc,
+      char** argv)
+{
+    NotifyNotification* notification;
+    gboolean            success;
+    GError*             error = NULL;
+    char                time2[200] = "";
+    char                *batt_percent;
+    struct tm *local;
+    time_t t;
+    int day;
+    int month;
+    int hour;
+    int min;
+    int week;
+    char months[][4] = {"Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"};
+    char wday[][4] = {"Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"};
+
+    // battery
+    batt_percent = batt(); 
+    strcat(time2, batt_percent);
+    strcat(time2, "\t");
+    free(batt_percent);
+
+    // Date and time:
+    t = time(NULL);
+    local = localtime(&t);
+    day = local->tm_mday;
+    hour = local->tm_hour;
+    min = local->tm_min;
+    month = local->tm_mon; //+1; 
+    week = local->tm_wday;    
+
+    
+    strcat(time2, wday[week]);
+    strcat(time2,"    ");
+    sprintf(time2, "%s%s", time2, months[month]); // sprintf para 2 str
+    strcat(time2," ");
+    sprintf(time2, "%s%d", time2, day);
+    strcat(time2,"\t");
+
+    sprintf(time2, "%s%d", time2, hour);
+    strcat(time2,":");
+    sprintf(time2, "%s%d", time2, min);
+
+    if (!notify_init ("summary-only"))
+        return 1;
+
+    notification = notify_notification_new (
+                time2,
+                NULL,
+                NULL);
+    error = NULL;
+    success = notify_notification_show (notification, &error);
+    if (!success){
+        g_print ("Erro ... \"%s\".\n", error->message);
+        g_error_free (error);
+    }
+    notify_uninit ();
+
+    return 0;
+}
+
+
+char *batt() {
+    //Populado por batt_monitor.py
+    FILE *arquivo = fopen("/home/fernando/.config/batt_statt", "rb");
+
+    if(arquivo != NULL){
+        fseek(arquivo, 0, SEEK_END);
+        long tam_arquivo = ftell(arquivo);
+        rewind(arquivo);
+
+        char *percentual = (char*) malloc(sizeof(char) * tam_arquivo);
+        
+        fread(percentual, 1, tam_arquivo, arquivo);
+        return percentual;
+    }
+    return (0);
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.