Spaces:
Running
Running
rsm-roguchi commited on
Commit ·
61c4d2f
1
Parent(s): 5a68d82
small changes
Browse files- app.py +6 -2
- server/ebay_time_away.py +61 -0
- server/meta.py +8 -6
- ui/ebay_time_away.py +14 -0
app.py
CHANGED
|
@@ -10,7 +10,8 @@ from ui import (
|
|
| 10 |
twitter,
|
| 11 |
price_matching,
|
| 12 |
inventory,
|
| 13 |
-
listing_checks
|
|
|
|
| 14 |
)
|
| 15 |
|
| 16 |
from server import (
|
|
@@ -20,7 +21,8 @@ from server import (
|
|
| 20 |
twitter as twitter_srv,
|
| 21 |
price_matching as price_matching_srv,
|
| 22 |
inventory as inventory_srv,
|
| 23 |
-
listing_checks as listing_checks_srv
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
|
|
@@ -33,6 +35,7 @@ ui = ui.page_fluid(
|
|
| 33 |
price_matching.ui,
|
| 34 |
inventory.ui,
|
| 35 |
listing_checks.ui,
|
|
|
|
| 36 |
title="SEO Blog Writer",
|
| 37 |
header=ui.tags.head(
|
| 38 |
ui.tags.link(rel='stylesheet', type='text/css', href='style.css')
|
|
@@ -48,5 +51,6 @@ def server(input, output, session):
|
|
| 48 |
price_matching_srv.server(input, output, session)
|
| 49 |
inventory_srv.server(input, output, session)
|
| 50 |
listing_checks_srv.server(input, output, session)
|
|
|
|
| 51 |
|
| 52 |
app = App(ui, server)
|
|
|
|
| 10 |
twitter,
|
| 11 |
price_matching,
|
| 12 |
inventory,
|
| 13 |
+
listing_checks,
|
| 14 |
+
ebay_time_away
|
| 15 |
)
|
| 16 |
|
| 17 |
from server import (
|
|
|
|
| 21 |
twitter as twitter_srv,
|
| 22 |
price_matching as price_matching_srv,
|
| 23 |
inventory as inventory_srv,
|
| 24 |
+
listing_checks as listing_checks_srv,
|
| 25 |
+
ebay_time_away as ebay_time_away_srv
|
| 26 |
)
|
| 27 |
|
| 28 |
|
|
|
|
| 35 |
price_matching.ui,
|
| 36 |
inventory.ui,
|
| 37 |
listing_checks.ui,
|
| 38 |
+
ebay_time_away.ui,
|
| 39 |
title="SEO Blog Writer",
|
| 40 |
header=ui.tags.head(
|
| 41 |
ui.tags.link(rel='stylesheet', type='text/css', href='style.css')
|
|
|
|
| 51 |
price_matching_srv.server(input, output, session)
|
| 52 |
inventory_srv.server(input, output, session)
|
| 53 |
listing_checks_srv.server(input, output, session)
|
| 54 |
+
ebay_time_away_srv.server(input, output, session)
|
| 55 |
|
| 56 |
app = App(ui, server)
|
server/ebay_time_away.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from shiny import reactive, render
|
| 2 |
+
from datetime import datetime, timedelta, date
|
| 3 |
+
import requests
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def get_next_sunday():
|
| 7 |
+
today = datetime.utcnow().date()
|
| 8 |
+
days_until_sunday = (6 - today.weekday()) % 7
|
| 9 |
+
return today + timedelta(days=days_until_sunday)
|
| 10 |
+
|
| 11 |
+
def activate_time_away(access_token: str, end_date: date):
|
| 12 |
+
url = "https://api.ebay.com/sell/account/v1/time_away"
|
| 13 |
+
headers = {
|
| 14 |
+
"Authorization": f"Bearer {access_token}",
|
| 15 |
+
"Content-Type": "application/json"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
now = datetime.utcnow()
|
| 19 |
+
end_datetime = datetime.combine(end_date, datetime.max.time())
|
| 20 |
+
|
| 21 |
+
payload = {
|
| 22 |
+
"startDate": now.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
| 23 |
+
"endDate": end_datetime.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
| 24 |
+
"timeAwayMode": "CUSTOM_MESSAGE",
|
| 25 |
+
"message": "Thanks for your message! We will get back to you soon! (Our business hours are M–F 9am–5pm)",
|
| 26 |
+
"autoDeclineRequests": False,
|
| 27 |
+
"hideFixedPriceStoreItems": False
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
resp = requests.put(url, headers=headers, json=payload)
|
| 31 |
+
return resp.status_code, resp.text
|
| 32 |
+
|
| 33 |
+
# Get your access token from environment
|
| 34 |
+
ACCESS_TOKEN = os.getenv("EBAY_USER_TOKEN")
|
| 35 |
+
|
| 36 |
+
def server(input, output, session):
|
| 37 |
+
# Reactive status value (clean fix)
|
| 38 |
+
status = reactive.Value("Click button to activate time away.")
|
| 39 |
+
|
| 40 |
+
@output
|
| 41 |
+
@render.text
|
| 42 |
+
def timeaway_status():
|
| 43 |
+
return status()
|
| 44 |
+
|
| 45 |
+
@reactive.effect
|
| 46 |
+
@reactive.event(input.activate_timeaway)
|
| 47 |
+
def _():
|
| 48 |
+
use_custom = input.use_custom_date()
|
| 49 |
+
selected_date = input.custom_end_date()
|
| 50 |
+
|
| 51 |
+
if use_custom and selected_date:
|
| 52 |
+
end_date = selected_date
|
| 53 |
+
else:
|
| 54 |
+
end_date = get_next_sunday()
|
| 55 |
+
|
| 56 |
+
code, msg = activate_time_away(ACCESS_TOKEN, end_date)
|
| 57 |
+
|
| 58 |
+
if code in [200, 204]:
|
| 59 |
+
status.set(f"✅ Time Away activated until {end_date.isoformat()}")
|
| 60 |
+
else:
|
| 61 |
+
status.set(f"❌ Failed: {msg}")
|
server/meta.py
CHANGED
|
@@ -93,12 +93,14 @@ def post_to_facebook(message: str) -> str:
|
|
| 93 |
"access_token": ACCESS_TOKEN
|
| 94 |
}
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
| 102 |
|
| 103 |
def server(input, output, session):
|
| 104 |
post_status = reactive.Value("")
|
|
|
|
| 93 |
"access_token": ACCESS_TOKEN
|
| 94 |
}
|
| 95 |
|
| 96 |
+
try:
|
| 97 |
+
response = requests.post(url, data=payload, timeout=10)
|
| 98 |
+
response.raise_for_status()
|
| 99 |
+
post_id = response.json().get("id", "Unknown")
|
| 100 |
+
return f"✅ Post successful! Facebook Post ID: {post_id}"
|
| 101 |
+
except requests.exceptions.RequestException as e:
|
| 102 |
+
return f"❌ Facebook post failed: {e}"
|
| 103 |
+
|
| 104 |
|
| 105 |
def server(input, output, session):
|
| 106 |
post_status = reactive.Value("")
|
ui/ebay_time_away.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from shiny import ui
|
| 2 |
+
from datetime import date
|
| 3 |
+
|
| 4 |
+
ui = ui.nav_panel(
|
| 5 |
+
"eBay Time Away",
|
| 6 |
+
|
| 7 |
+
ui.input_checkbox("use_custom_date", "Use custom end date", value=False),
|
| 8 |
+
|
| 9 |
+
ui.input_date("custom_end_date", "Select end date (UTC)", value=date.today()),
|
| 10 |
+
|
| 11 |
+
ui.input_action_button("activate_timeaway", "Activate Time Away", class_="btn-primary"),
|
| 12 |
+
|
| 13 |
+
ui.output_text("timeaway_status")
|
| 14 |
+
)
|