import json
import os
import requests
from markdown_it import MarkdownIt
def create_article(title, access_token):
headers = {
"X-API-Access-Token": access_token,
"Content-Type": "application/json"
}
data = {
"title": title,
"body": "TEST",
"tags": "REDACTED",
"article_type": "knowledge-article",
"filter": "default"
}
json_data = json.dumps(data)
api_url = "https://api.stackoverflowteams.com/2.3/articles/add?team=[TEAM_NAME]"
response = requests.post(api_url, headers=headers, data=json_data)
print(f"API response status: {response.status_code}")
print(f"API response text: {response.text}")
return response.json()
def delete_article(access_token, artId):
headers = {
"X-API-Access-Token": access_token,
"Content-Type": "application/json"
}
data = {
"id": artId
}
json_data = json.dumps(data)
api_url = f"https://api.stackoverflowteams.com/2.3/articles/{artId}/delete?team=[TEAM_NAME]"
response = requests.delete(api_url, headers=headers, data=json_data)
print(f"API response status: {response.status_code}")
print(f"API response text: {response.text}")
return response.json()
def import_single_wiki_to_teams(input_directory, access_token, test_file):
input_file = os.path.join(input_directory, test_file)
if os.path.isfile(input_file):
with open(input_file, "r", encoding="utf-8") as f:
content = f.read()
html_content = convert_md_to_html(content)
# title = os.path.splitext(test_file)[0]
title = "TeArticle"
print(f"Title from OS is: {title!r}")
response = create_article('Test Article', access_token) # Use the title and html_content variables
print(response)
else:
print(f"File not found: {input_file}")
input_directory = PATH
access_token = [REDACTED]
test_file = "FILE_NAME"
import_single_wiki_to_teams(input_directory, access_token, test_file)
import json
import os
import requests
from markdown_it import MarkdownIt
def create_article(title, access_token):
headers = {
"X-API-Access-Token": access_token,
"Content-Type": "application/json"
}
data = {
"title": title,
"body": "TEST",
"tags": "REDACTED",
"article_type": "knowledge-article",
"filter": "default"
}
json_data = json.dumps(data)
api_url = "https://api.stackoverflowteams.com/2.3/articles/add?team=[TEAM_NAME]"
response = requests.post(api_url, headers=headers, data=json_data)
print(f"API response status: {response.status_code}")
print(f"API response text: {response.text}")
return response.json()
def delete_article(access_token, artId):
headers = {
"X-API-Access-Token": access_token,
"Content-Type": "application/json"
}
data = {
"id": artId
}
json_data = json.dumps(data)
api_url = f"https://api.stackoverflowteams.com/2.3/articles/{artId}/delete?team=[TEAM_NAME]"
response = requests.delete(api_url, headers=headers, data=json_data)
print(f"API response status: {response.status_code}")
print(f"API response text: {response.text}")
return response.json()
def import_single_wiki_to_teams(input_directory, access_token, test_file):
input_file = os.path.join(input_directory, test_file)
if os.path.isfile(input_file):
with open(input_file, "r", encoding="utf-8") as f:
content = f.read()
html_content = convert_md_to_html(content)
# title = os.path.splitext(test_file)[0]
title = "TeArticle"
print(f"Title from OS is: {title!r}")
response = create_article('Test Article', access_token) # Use the title and html_content variables
print(response)
else:
print(f"File not found: {input_file}")
input_directory = PATH
access_token = [REDACTED]
test_file = "FILE_NAME"
import_single_wiki_to_teams(input_directory, access_token, test_file)