Skip to content

Instantly share code, notes, and snippets.

View samirsaci's full-sized avatar

Samir Saci samirsaci

View GitHub Profile
@samirsaci
samirsaci / import.py
Last active March 8, 2021 22:07
Telegram Bot - Import Libs
import logging
import os
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Update
from telegram.ext import (
Updater, CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackContext
)
from scrapping import *
from mail import *
import requests
@samirsaci
samirsaci / main.py
Created March 8, 2021 19:57
Telegram Bot - Main Function
def main():
'''Start Bot'''
# Launch Updater
updater = Updater("{}".format(TOKEN), use_context=True)
# Get the dispatcher to register handlers
dispatcher = updater.dispatcher
# conversions handled by command
dispatcher.add_handler(CommandHandler("start", start))
@samirsaci
samirsaci / photo.py
Created March 8, 2021 20:49
Telegram Bot - Photo
def photo(update: Update, context: CallbackContext):
user = update.message.from_user
photo_file = update.message.photo[-1].get_file()
# photo_file.download('user_photo.jpg')
# Get link to get file_path
link1 = "https://api.telegram.org/bot{}/getfile?file_id={}".format(TOKEN, photo_file.file_id)
r = requests.get(link1)
file_path = r.json()["result"]["file_path"]
@samirsaci
samirsaci / selenium.py
Created March 13, 2021 17:57
Initialize Selenium Bot
import os
from selenium import webdriver
from bs4 import BeautifulSoup as soup
# Chromedrive setting
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
def from_to(fr, to):
# create irl
url = 'https://www.google.fr/maps/dir/{}/{}/data=!4m2!4m1!3e0'.format(fr, to)
# Connect to the page
driver.get(url)
# Wait 1 sec to ensure full page is loaded
time.sleep(1)
# Soupify source code
page_soup = soup(driver.page_source, "html.parser")
# Extract Distance
@samirsaci
samirsaci / flask_app.py
Last active March 13, 2021 20:08
Flask API Google Maps
from flask import Flask, render_template, request, redirect
app = Flask(__name__)
# Home Page
@app.route('/')
def index():
return render_template('index.html')
# Distance Page
@samirsaci
samirsaci / luxury_online.csv
Last active March 16, 2021 21:10
Matrix Diagram - Dataset head
DATE FORMAT ORDER_NUMBER SKU PCS BRAND
2018-12-10 3737303 448502 1 Lancome
2018-12-10 3737303 307110 1 Lauder
2018-12-10 3743178 444803 1 Marie Dalgar Co
2018-12-01 3752413 292713 1 Givenchy
2018-12-01 3752414 216152 1 Shiseido
2018-12-01 3752416 401707 1 Marie Dalgar Co
2018-12-01 3752417 347741 1 Guerlain
2018-12-01 3752418 441223 1 Givenchy
2018-12-01 3752422 458573 1 Esthederm
{
"nodes": [
{
"name": "Myriel",
"group": 1
},
{
"name": "Napoleon",
"group": 1
}
@samirsaci
samirsaci / nodes.py
Created March 19, 2021 20:52
Create nodes
def order_brand(PATH_IN):
''' List of all brands in each order'''
# Import DataFrame
df_rec = pd.read_excel(PATH_IN)
# Listing Unique Brands
df_ordbr = pd.DataFrame(df_rec.groupby(['ORDER_NUMBER'])['BRAND'].unique())
df_ordbr.columns = ['list_brand']
# source = list brands
def create_links(df_rec, df_ordbr, list_brand):
''' Create links dataframe '''
# Unique brands per order
df_source = pd.DataFrame(df_rec.groupby(['ORDER_NUMBER'])['BRAND'].unique())
df_source.columns = ['list_brand']
list_source, list_target, list_value = [], [], []
for br1 in list_brand:
for br2 in list_brand: