import time amount = {} import time, re, getpass, os, csv from lib import Plugin, cron plgn = Plugin('daily_notes') logger = plgn.logger fieldnames = ['Date', 'Seperator', 'Todo', 'Type'] @plgn.command('remind\Z') def receiving(data): retrieving() return sending_back(retrieving()) def retrieving(*args): global fieldnames task_status = {'Pending': [], 'Done': []} with open('daily-task.csv', 'r') as f: final = "" r = csv.DictReader(f) for row in r: if args: f = fieldnames[args[1]] if args[0] in row[str(f)]: temp = ' '.join( [value for key, value in row.items() if key != 'Type']) if row['Type'] == 'Pending': task_status['Pending'].append(temp)
import os import json from datetime import datetime from csv import DictReader, DictWriter from lib import Plugin, cron plgn = Plugin('share') logger = plgn.logger all = ['soumavo', 'bos', 'sumit'] def addToTable(table, p, n): sp = sorted(p.items(), key=lambda (x, y): y, reverse=True) sn = sorted(n.items(), key=lambda (x, y): y, reverse=True) for i in range(len(sn)): name, toGive = sn[i] if toGive: for j in range(len(sp)): (otherName, toReceive) = sp[j] if toReceive: if toGive >= toReceive: toGive -= toReceive sp[j] = (otherName, 0) sn[i] = (name, toGive) table[name][otherName] = table[name].get(otherName, 0) + toReceive #print '%s gives %s Rs. %d'%(name,otherName,toReceive) else: sp[j] = (otherName, toReceive - toGive)
import requests from itertools import repeat from lib import Plugin, cron plgn = Plugin('managerclient') logger = plgn.logger @plgn.command('exe (?P<config>(\d+,)*\d+)') def exercise(data, **details): """ Store exe related data """ URL = plgn.managerurl + '/daily' r = requests.post(URL, data={ 'type': 'exercise', 'data': details['config'] }, verify=False) if r.status_code == 201: return 'Ok' else: return 'Failed to inform the server, please try again' @plgn.schedule(maximum=1) def ping(): for url in plgn.URLS: logger.info('pinging %s' % url) r = requests.get(url, verify=False)
import time import re,getpass,os,time amount = {} from lib import Plugin, cron plgn = Plugin('wallet') logger = plgn.logger def making_database(): f = open("wallet.txt",'w') string = "{'cash':0,'savings':0,'pay':{},'receive':{}}" f.write(string) f.write("\n") f.close() logger.info("Database written") def reading_database(): global amount f = open("wallet.txt",'r') data = f.read() f.close() amount = eval(data) logger.info("Database_read") def updating_database(): global amount f=open("wallet.txt",'w') f.write(str(amount)) f.close() logger.info("database_updated")
import time import re, urbandict from lib import Plugin plgn = Plugin('dictionay') @plgn.command('define (?P<what>[-a-zA-Z]+)') def temp(data, what): final = "" d = urbandict.define(str(what)) for item in d: final = final + item['def'] return final @plgn.command('use (?P<what>[-a-zA-Z]+)') def temp(data, what): final = "" d = urbandict.define(str(what)) for item in d: final = final + item['example'] return final
import os,subprocess import sys import logging from logging.handlers import RotatingFileHandler import re,youtube_dl,getpass,os from lib import Plugin, cron plgn = Plugin('youtube') logger = plgn.logger ydl_logger = logging.getLogger(__name__) if len(ydl_logger.handlers) < 1: ydl_handler = RotatingFileHandler('youtubedl.log', 'a', 2 * 1024 * 1024) ydl_handler.propagate = False ydl_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s')) ydl_logger.addHandler(ydl_handler) ydl_logger.setLevel(logging.DEBUG) # downloaded_list is a global variable for storing the names of the videos which are downloaded # by link_downloader. This is used for parsing video names form downloader_hook to the download # function so that it can be returned to inform the user. This is just a temporary solution. # In the long run, may be modifying the thread class to include a list would be a better option. downloaded_list = [] @plgn.command('tell') def tell(data,what=None): string = """Follow the following commands : download (link) [a] This function lets you download a video or audio directly. 'a' is optional parameter for downloading the audio file. queue Returns a list of all links that are noted in download_queue.txt
import time import re from lib import Plugin, cron plgn = Plugin('repeat') logger = plgn.logger plgn.__doc__ = "Demo/Dummy plugin" @plgn.command( 'repeat (?P<what>[-a-zA-Z0-9 `,;!@#$%^&*()_=.{}:"\?\<\>/\[\'\]\\n]+)') def repeat(data, what): return 'repeating ' + what #@plgn.schedule(cron(second=range(0,60,5)), maximum = 2) #def logr(*args, **kwargs): # plgn.myid =myid= getattr(plgn,'myid',0) + 1 # logger.info('start myid is %s' % myid) # time.sleep(20) # logger.info('end myid is %s' % myid)
import os from itertools import repeat from lib import Plugin, cron plgn = Plugin('watch') logger = plgn.logger """ http://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid-in-python """ if os.name == 'posix': def pid_exists(pid): """Check whether pid exists in the current process table.""" import errno if pid < 0: return False try: os.kill(pid, 0) except OSError as e: return e.errno == errno.EPERM else: return True else: def pid_exists(pid): import ctypes kernel32 = ctypes.windll.kernel32 SYNCHRONIZE = 0x100000 process = kernel32.OpenProcess(SYNCHRONIZE, 0, pid) if process != 0:
import os from datetime import datetime import logging from csv import DictWriter, DictReader from lib import Plugin, cron from collections import defaultdict logger = logging.getLogger('bot.reimburse') logger.setLevel(logging.DEBUG) plgn = Plugin('reimburse') plgn.__doc__ = "Use this plugin to store reimbursements. The details will be mailed to you by the end of month" @plgn.command('reim (?P<amt>-?\d+) (?P<why>[A-Za-z0-9 !@#$%^&*()]+)') def save(data, **details): """ save reimbursement details: usage: reim <amt> <why> """ with open(plgn.exp_filename, 'a') as f: wr = DictWriter(f, ['dt','by','amt', 'why','status']) dt = datetime.now() details['status'] = 1 details['dt'] = dt details['by'] = data['user_object'].name if data.get('user_object') else data['user'] wr.writerow(details) sendMonthlyEmail(None, **details) return '{amt} was spent for {why}'.format(**details)
import os from datetime import datetime from csv import DictWriter, DictReader from lib import Plugin, cron from collections import defaultdict plgn = Plugin('reimburse') logger = plgn.logger plgn.__doc__ = "Use this plugin to store reimbursements. The details will be mailed to you by the end of month" @plgn.command('reim (?P<amt>-?\d+) (?P<why>[A-Za-z0-9 !@#$%^&*()]+)') def save(data, **details): """ save reimbursement details: usage: reim <amt> <why> """ with open(plgn.exp_filename, 'a') as f: wr = DictWriter(f, ['dt', 'by', 'amt', 'why', 'status']) dt = datetime.now() details['status'] = 1 details['dt'] = dt details['by'] = data['user_object'].name if data.get( 'user_object') else data['user'] wr.writerow(details) sendMonthlyEmail(None, **details) return '{amt} was spent for {why}'.format(**details) def userwise(): """
import os import pickle from lib import Plugin plgn = Plugin('todo') logger = plgn.logger tasks = {} FILE = "todo.data" if os.path.isfile(FILE): tasks = pickle.load(open(FILE, 'rb')) @plgn.command('tasks|fin|done|show|todo') def todo(data, **args): global tasks channel = data["channel"] text = data["text"] #only accept tasks on DM channels if channel.startswith("D"): if channel not in tasks.keys(): tasks[channel] = [] #do command stuff if text.startswith("todo"): tasks[channel].append(text[5:]) return 'added' if text == "tasks": output = "" counter = 1 for task in tasks[channel]: output += "%i) %s\n" % (counter, task)
import time import re from lib import Plugin, cron import logging logger = logging.getLogger("bot.repeat") logger.setLevel(logging.DEBUG) plgn = Plugin("repeat") plgn.__doc__ = "Demo/Dummy plugin" @plgn.command("repeat (?P<what>[-a-zA-Z0-9 `,;!@#$%^&*()_=.{}:\"\?\<\>/\['\]\\n]+)") def repeat(data, what): return "repeating " + what # @plgn.schedule(cron(second=range(0,60,5)), maximum = 2) # def logr(*args, **kwargs): # plgn.myid =myid= getattr(plgn,'myid',0) + 1 # logger.info('start myid is %s' % myid) # time.sleep(20) # logger.info('end myid is %s' % myid)
import time, requests import re, getpass, os, time, csv a = [] from lib import Plugin, cron plgn = Plugin('link') logger = plgn.logger @plgn.command( 'Url (?P<what>[-a-zA-Z0-9 `,;!@#$%^&*()_=.{}:"\?\<\>/\[\'\]\\n]+)') def experiment(data, what): if not os.access('data.csv', os.F_OK): data_write(' ', ' ', ' ') a = time.asctime(time.localtime(time.time())) x = what.split(" ") if len(x) > 1: description = " ".join(x[1:]) what = x[0] else: description = " " temp = list(what) if '>' in temp: temp.remove('>') if '<' in temp: temp.remove('<') what = "".join(temp) #filter to check if the link exists and is valid if requests.get(what).status_code != 200:
import requests import time from bs4 import BeautifulSoup from lib import Plugin, cron plgn = Plugin('actlogin') logger = plgn.logger password = username = URL = '' @plgn.schedule(cron(hour=[5], minute=[0], second=[0])) def relogin(): logger.info('Now Logging out') logout() logger.info('Logged Out successfully') time.sleep(10) logger.info('Logging in now') login() logger.info('Logged in successfully') #plgn.outputs.append(['random', 'Relogged in successfully']) def login(): resp = requests.get(URL) l = resp.content logger.debug("got content") bs = BeautifulSoup(l) f = bs.findAll('form')[1] logger.debug("found form")