Ejemplo n.º 1
0
    def _send_email(self, compare_result):
        """ send the compare result to recipients """
        subject = "JDSports update - " + datetime.now().strftime("%m/%d %H:%M")
        html = ""

        if len(compare_result["new"]) > 0:
            html += self._products_to_html("New", compare_result["new"])

        if len(compare_result["removed"]) > 0:
            html += self._products_to_html("Removed",
                                           compare_result["removed"])

        if len(compare_result["changed"]) > 0:
            html += self._products_to_html("Changed",
                                           compare_result["changed"])

        #if len(compare_result["identical"]) > 0:
        #    html += self._products_to_html("Identical", compare_result["identical"])

        Gmail(self.sender["id"], self.sender["password"], self.recipients,
              subject, html).send()
Ejemplo n.º 2
0
from Gmail import Gmail
from Whatsapp import Whatsapp

chrome_options = ChromeOptions()
chrome_options.set_capability('unhandledPromptBehavior', 'accept')

driver = webdriver.Chrome(ChromeDriverManager().install(),
                          options=chrome_options)
wait = WebDriverWait(driver, 600)

with open("credentials.json", "r", encoding="utf8") as f:
    data = json.load(f)
    whatsapp_contacts = data["contacts"]["whatsapp"]
    gmail_contacts = data["contacts"]["Gmail"]

GOOGLE = Gmail(driver, wait)
WHATSAPP = Whatsapp(driver, wait)


def get_presentable_json(json_str):
    final_string = "contacts:\n"
    i = 0
    final_string = "contacts"
    for contact in json_str:
        final_string += contact
        final_string += f"({i})\n"
        i += 1
    return final_string


def handle_gmail_client():
Ejemplo n.º 3
0
    parser = argparse.ArgumentParser(parents=[argparser])
    flags = parser.parse_args()

    # Ouverture de la base de données
    try:
        print 'Ouverture de la base <links.db>'
        base = sqlite3.connect('links.db')
        cursor = base.cursor()
        cursor.execute(
            'create table links (id integer primary key, tag text, url text);')
        base.commit()
        print 'Table <links> créée !'
    except sqlite3.OperationalError:
        print 'Table <links> trouvée !'

    gmail = Gmail(flags,
                  oauth_scope='https://www.googleapis.com/auth/gmail.modify')
    messages = gmail.getMessagesList(query='is: unread')
    pattern = re.compile(r'^\[#(\w+)\]')

    if messages['messages']:
        for msg in messages['messages']:
            m = gmail.getMessageDetails(msg['id'])
            if m.getFrom().startswith('Tristan Colombo'):
                subject = m.getSubject()
                tag = pattern.search(subject)
                if tag is not None:
                    link = m.getSnippet()
                    print 'Ajout du lien {} avec le tag {}'.format(
                        link, tag.group(1))
                    cursor.execute(
                        'insert into links(tag, url) values("{}", "{}");'.
# -*-coding:utf-8-*-
import argparse
from oauth2client.tools import argparser
from Gmail import Gmail

if __name__ == '__main__':
    parser = argparse.ArgumentParser(parents=[argparser])
    flags = parser.parse_args()
    json_file =  "client_secret.json"
    sender =  "*****@*****.**"
    to = "*****@*****.**"
    message = "c'est un test"
    subject =  "essai"
    filename = "message_test.txt"

    gmail = Gmail(flags, client_secret_file =json_file, oauth_scope = 'https://www.googleapis.com/auth/gmail.readonly')

    #gmail = Gmail(flags, oauth_scope = 'https://www.googleapis.com/auth/gmail.readonly')
    messages = gmail.getMessagesList()

    if messages['messages']:
        for msg in messages['messages']:
            #print msg
            print 'Msg id = {}'.format(msg['id'])
            m = gmail.getMessageDetails(msg['id'])
            #print m.data

            print 'From : {}'.format(m.getFrom())
            print 'To : {}'.format(m.getTo())
            print 'Subject : {}'.format(m.getSubject())
            #print 'Filename : {}'.format(m.getAttachment(gmail.gmail_service, to, msg['id']))