Skip to content

Instantly share code, notes, and snippets.

View micheleberardi's full-sized avatar
:octocat:
Life is good

Michele micheleberardi

:octocat:
Life is good
View GitHub Profile
@micheleberardi
micheleberardi / script_import_tensoflow
Created September 11, 2019 20:42
script_import_tensoflow
#sudo apt-get install libmysqlclient-dev
#pip install mysqlclient
import csv
import MySQLdb
import tensorflow as tf
mydb = MySQLdb.connect(host='localhost',
user='root',
passwd='root')
cursor = mydb.cursor()
@micheleberardi
micheleberardi / class_example
Created October 10, 2019 15:45
simple clss
import requests
class Authorization:
def __init__(self, username, password, company_uid):
self.username = username
self.password = password
self.company_uid = company_uid
def token(self):
url = "https://api.domain.com/3.0/login/?username=" + self.username + "&password=" + self.password + "&company_uid=" + self.company_uid + ""
#!/usr/bin/env python3.7
# -*- coding: utf-8 -*-
__author__ = "Michele Berardi"
__copyright__ = "Copyright 2020"
__license__ = "GPL"
__version__ = "1.0.8"
__maintainer__ = "Michele Berardi"
__email__ = "michele@linux.com"
__status__ = "Production"
import subprocess
import os
import subprocess
import requests
def is_service_running(name):
with open(os.devnull, 'wb') as hide_output:
exit_code = subprocess.Popen(['service', name, 'status'], stdout=hide_output, stderr=hide_output).wait()
return exit_code == 0
@micheleberardi
micheleberardi / google_importer.py
Last active February 19, 2022 22:56
Google Retail import into Big Query
from modules import defines
import ndjson
from google.cloud import bigquery
import pymysql
database = pymysql.connect(host='IP', user='USER', passwd='PWD', db='DB_NAME',use_unicode=True, cursorclass=pymysql.cursors.DictCursor, charset="utf8")
def select_exe(query_select):
mydb = pymysql.connect(host='IP', user='USER', passwd='PWD', db='DB_NAME',use_unicode=True, cursorclass=pymysql.cursors.DictCursor, charset="utf8")
try:
[
{
"name": "product_metadata",
"type": "RECORD",
"mode": "NULLABLE",
"fields": [
{
"name": "images",
"type": "RECORD",
"mode": "REPEATED",
@micheleberardi
micheleberardi / example_dict.txt
Last active February 19, 2022 23:06
example_google_retails
{"id": sku,"categories":categories],"title":description,"priceInfo":[{"currencyCode":"USD"},{"price":float(exact_price)},{"originalPrice":float(exact_price)},{"cost":float(exact_price)}]}
@micheleberardi
micheleberardi / script_cron
Created February 19, 2022 23:16
script_cron
gcloud scheduler --project micheleone \
jobs create http import_catalog_xmq5ynl8i2i \
--time-zone='America/Los_Angeles' \
--schedule='0 0 * * *' \
--uri='https://retail.googleapis.com/v2alpha/projects/***********/locations/global/catalogs/default_catalog/branches/1/products:import' \
--description='Import Retail catalog data' \
--headers='Content-Type: application/json; charset=utf-8' \
--http-method='POST' \
--message-body='{"inputConfig":{"bigQuerySource":{"projectId":"project-id","datasetId":"retail","tableId":"catalog","dataSchema":"product"}},"reconciliationMode":"INCREMENTAL"}' \
--oauth-service-account-email=''
@micheleberardi
micheleberardi / def_ig_media.py
Created July 12, 2022 19:29
GET IG MEDIA LIST
import requests
def get_url(instagram_profile_id,instagram_token):
url = "https://graph.facebook.com/v14.0/"+str(instagram_profile_id)+"/media?fields=id%2Ccaption%2Cis_comment_enabled%2Ccomments_count%2Clike_count%2Cmedia_type%2Cmedia_url%2Cpermalink&access_token="+str(instagram_token)
r = requests.get(url)
return r.json()