-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab556f0
commit 7e14750
Showing
8 changed files
with
74 additions
and
20 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
# import .env file | ||
from decouple import config | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
|
||
load_dotenv() | ||
|
||
access_token = os.getenv('ACCESS_TOKEN') | ||
|
||
class Auth: | ||
""" Authenticate with HubSpot """ | ||
@staticmethod | ||
def get_token(): | ||
# get HubSpot private app token from input | ||
# token = input('Enter your HubSpot private app token: ') | ||
# return token from .env file | ||
access_token = config('ACCESS_TOKEN') | ||
return access_token | ||
# Get the HubSpot private app token from environment variables | ||
access_token = os.environ.get('ACCESS_TOKEN') | ||
print(access_token) | ||
if not access_token: | ||
raise ValueError("ACCESS_TOKEN not found. Declare it as envvar or define a default value.") | ||
return access_token | ||
|
||
|
||
Auth.get_token() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import argparse | ||
import json | ||
import pandas as pd | ||
from hubmigrate.client import MigrationClient | ||
from dotenv import load_dotenv | ||
import os | ||
|
||
|
||
load_dotenv() | ||
|
||
|
||
def read_file(file_path, data_type): | ||
if data_type == 'json': | ||
with open(file_path, 'r') as file: | ||
return json.load(file) | ||
elif data_type == 'excel': | ||
if file_path.endswith('.xlsx'): | ||
return pd.read_excel(file_path, engine='calamine').to_dict(orient='records') | ||
elif file_path.endswith('.xls'): | ||
return pd.read_excel(file_path, engine='xlrd').to_dict(orient='records') | ||
else: | ||
raise ValueError("Unsupported Excel file format") | ||
elif data_type == 'csv': | ||
return pd.read_csv(file_path).to_dict(orient='records') | ||
else: | ||
raise ValueError("Unsupported data type") | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Migrate data to HubSpot") | ||
|
||
parser.add_argument('object_type', choices=['contacts', 'companies'], help="Type of object to migrate") | ||
parser.add_argument('file_path', help="Path to the data file (JSON, Excel, or CSV)") | ||
parser.add_argument('data_type', choices=['json', 'excel', 'csv'], help="Type of data file") | ||
parser.add_argument('--config', default='config', help="Path to the config file") | ||
parser.add_argument('--hubspot', default='hubspot', help="HubSpot portal name") | ||
|
||
args = parser.parse_args() | ||
|
||
data = read_file(args.file_path, args.data_type) | ||
|
||
client = MigrationClient(args.config, args.hubspot) | ||
|
||
if args.object_type == 'contacts': | ||
response = client.migrate_contact(data) | ||
elif args.object_type == 'companies': | ||
print(data) | ||
response = client.migrate_company(data) | ||
|
||
print(response) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ pytest | |
coverage | ||
python-decouple | ||
requests | ||
pandas | ||
pandas | ||
python-decouple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
{ | ||
"name": "Politie Utrecht", | ||
"country": "Netherlands", | ||
"city": "Utrecht", | ||
"address": "Marco Pololaan 215", | ||
"zip": "3526GB", | ||
"website": "https://www.politie.nl/", | ||
"phone": "0900-8844" | ||
"name": "Politie Utrecht" | ||
} | ||
|
This file was deleted.
Oops, something went wrong.