Created
September 10, 2024 02:58
-
-
Save wezoalves/5e2455cf158833ff797d40f01ed4e575 to your computer and use it in GitHub Desktop.
Update meta values into post WordPress
This file contains hidden or 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
import pandas as pd | |
import requests | |
import time | |
from requests.auth import HTTPBasicAuth | |
def update_post_meta(post_id, meta_key, meta_value, wp_user, wp_password, wp_url): | |
url = f"{wp_url}/wp-json/ra/v1/update-meta" | |
data = { | |
"post_id": post_id, | |
"meta_key": meta_key, | |
"meta_value": meta_value | |
} | |
auth = HTTPBasicAuth(wp_user, wp_password) | |
response = requests.post(url, json=data, auth=auth) | |
if response.status_code == 200: | |
print(f"Meta field atualizado para o post {post_id}") | |
else: | |
print(f"Erro ao atualizar o post {post_id}: {response.status_code}, {response.text}") | |
def read_csv(file_path): | |
df = pd.read_csv(file_path) | |
return df | |
def main(): | |
wp_url = "https://domain.com/" | |
wp_user = "user-wordpress" | |
wp_password = "password-app-wordpress" | |
meta_key = "key-meta" | |
meta_value = "value-meta" | |
file_path = "file-source-ids.csv" | |
df = read_csv(file_path) | |
for post_id in df['ID']: # Substitua 'ID' pelo nome da coluna no csv | |
update_post_meta(post_id, meta_key, meta_value, wp_user, wp_password, wp_url) | |
time.sleep(3) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment