Sindbad~EG File Manager
from flask import request, Blueprint, jsonify, redirect, url_for,flash, render_template,session,json,render_template_string,Response,send_file
import requests
from .. import Cryptography,Auth,RouteGroup,Helper
from datetime import timedelta,date,datetime
from collections import defaultdict
app = Blueprint('test', __name__)
@app.route('test', methods = ["GET", "POST"])
def Test():
title_data = TestModel().tmp_abs_title_case_conv()
# print(title_data[0])
for i in title_data:
# print(i)
orginal_title = i.get('orginal_title') or None
orginal_synopsis = i.get('orginal_synopsis') or None
if orginal_title:
new_title = ama_title_case(orginal_title)
new_synopsis = ama_title_case(orginal_synopsis)
#
# url = "https://title-case-converter.p.rapidapi.com/v1/TitleCase"
# # querystring = {"title":"thanks for opting in to stay in touch","style":"AMA","preserveAllCaps":"0","tagSpeciesNames":"0"}
# querystring = {"title":"CROSSECTIONAL STUDY OF ACA PARAMETERS IN SHALLOW AC PROBANDS & THEIR SIBLINGS AT A TERTIARY CENTRE CROSSECTIONAL STUDY OF ACA PARAMETERS IN SHALLOW AC PROBANDS & THEIR SIBLINGS AT A TERTIARY CENTRE CROSSECTIONAL STUDY OF ACA PARAMETERS IN SHALLOW AC PROBANDS & THEIR SIBLINGS AT A TERTIARY CENTRE CROSSECTIONAL STUDY OF ACA PARAMETERS IN SHALLOW AC PROBANDS & THEIR SIBLINGS AT A TERTIARY CENTRE","style":"AMA","preserveAllCaps":"0","tagSpeciesNames":"0"}
# print("------querystring---",querystring)
# headers = {
# "x-rapidapi-key": "ac0c86d3ecmshb466fcf4fe3732bp1521aajsn6b76ebc9f61d",
# "x-rapidapi-host": "title-case-converter.p.rapidapi.com"
# }
# response = requests.get(url, headers=headers, params=querystring)
# result = response.json()
# print(result)
# print(result['result'])
i['new_title'] = new_title
i['new_synopsis'] = new_synopsis
print(title_data[0])
TestModel().update_titile_data(title_data)
# return "load done"
return jsonify(title_data)
def ama_title_case(title):
if title:
"""
Converts a string into AMA-style title case.
The first word is always capitalized. Other words are capitalized unless they are in the list of
exceptions (minor words) such as articles, conjunctions, and prepositions.
Args:
title (str): The input title string.
Returns:
str: The title converted to AMA title case.
"""
# Define a set of minor words that should remain lowercase (unless they are the first word)
minor_words = {
'a', 'an', 'the', 'and', 'but', 'or', 'nor', 'for', 'so', 'yet',
'at', 'by', 'in', 'of', 'on', 'to', 'up', 'as', 'with', 'from'
}
# Split the title into words
words = title.split()
# Process each word: always capitalize the first word;
# for the rest, if they are in minor_words, make them lowercase, else capitalize.
processed_words = []
for i, word in enumerate(words):
if i == 0:
# Always capitalize the first word
processed_words.append(word.capitalize())
else:
# Lowercase the word if it is a minor word, otherwise capitalize
if word.lower() in minor_words:
processed_words.append(word.lower())
else:
# For words that might include punctuation (e.g., "cancer:"), handle it carefully.
# We'll split off punctuation at the end.
if word[-1] in ":;,.!?":
core = word[:-1]
punct = word[-1]
processed_words.append(core.capitalize() + punct)
else:
processed_words.append(word.capitalize())
return " ".join(processed_words)
else:
return None
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists