PHP 7.4.33
Preview: README.md Size: 2.86 KB
/home/godevadmin/public_html/upload_images/home/000~ROOT~000/python-scripts-home/README.md

# Quicklly Google Merchant Product Upload

This project automates the upload and deletion of products to Quicklly’s Google Merchant Center using the Content API.

---

## 📁 Project Structure

```
Google Merchant Product Upload/
├── merchant_upload.py
├── requirements.txt
├── README.md
├── handoff.pdf
├── keys/
│   └── quicklly-merchant-center.json
├── tools
    └── delete_all_products.py
    └── delete_select_products.py
```

---

## Setup Instructions

### 1. Create a Virtual Environment (Optional but Recommended)

```bash
python3 -m venv env
source env/bin/activate
```

### 2. Install Dependencies

```bash
pip install -r requirements.txt
```

---

## Credentials Setup

Place the provided **`quicklly-merchant-center.json`** file in:

```bash
./keys/quicklly-merchant-center.json
```

Make sure this matches the path in your script:

```python
SERVICE_ACCOUNT_FILE = './keys/quicklly-merchant-center.json'
```

---


## Running the Script

```bash
python merchant_upload.py
```

---

## Deleting Products

Delete a single product by offerId
Use this to quickly remove an individual product from Google Merchant Center:

```bash
python tools/delete_product.py <offerId>
```

Delete all products (use with caution!)
Wipes the entire product catalog. Use only for staging/testing environments or after confirmation:
```bash
python tools/delete_all_products.py
```

## Automating with Cron

### Every 2 Minutes

```bash
*/2 * * * * /usr/bin/python3 /path/to/Google\ Merchant\ Product\ Upload/merchant_upload.py >> /var/log/merchant_upload.log 2>&1
```

### Every 2 Hours

```bash
0 */2 * * * /usr/bin/python3 /path/to/Google\ Merchant\ Product\ Upload/merchant_upload.py >> /var/log/merchant_upload.log 2>&1
```

> Ensure proper file permissions and review log output regularly.

---

## Regional Inventory Mapping

The script automatically assigns products to predefined regions based on the product’s `"city"` field using a dictionary like:

```python
CITY_TO_REGION_ID = {
  "chicago": "region_chi",
  "new york": "region_nyc",
  "los angeles": "region_la",
  "san francisco": "region_sf"
}
```

If a product’s city doesn’t match this mapping, no regional inventory will be sent.

---

## How to Expand to Hundreds of Regions

1. In Google Merchant Center, go to:
   ```
   Products → Regional availability and pricing → Region definitions
   ```

2. Create new regions with:
   - A **region ID** (at least 6 characters, e.g., `region_dallas`)
   - A large enough set of ZIP codes (30–100+ per region is recommended)

3. Update your script's mapping:
   ```python
   CITY_TO_REGION_ID["dallas"] = "region_dallas"
   ```

For large-scale rollout, this mapping can also be loaded from a CSV, database, or admin panel.

---

## Notes

- **Merchant ID:** `5616033984`  
- **API Scope:** `https://www.googleapis.com/auth/content`  
- **Region:** `US`  

Directory Contents

Dirs: 4 × Files: 4

Name Size Perms Modified Actions
keys DIR
- drwxr-xr-x 2025-07-22 17:20:04
Edit Download
logs DIR
- drwxr-xr-x 2025-07-22 18:23:22
Edit Download
- drwxr-xr-x 2025-07-31 17:00:29
Edit Download
tools DIR
- drwxr-xr-x 2025-07-31 17:01:47
Edit Download
10.65 KB lrw-r--r-- 2025-07-31 17:03:46
Edit Download
127 B lrwxrwxrwx 2025-07-23 16:56:47
Edit Download
2.86 KB lrw-r--r-- 2025-07-22 17:19:18
Edit Download
46 B lrw-r--r-- 2025-07-22 17:19:18
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).