audit integration

This commit is contained in:
Ubuntu 2024-04-30 07:33:51 +00:00
parent 5a50a95ccf
commit 0d18c56f01
4 changed files with 839 additions and 30 deletions

View File

@ -0,0 +1,713 @@
"""
Django settings for MNF project.
Generated by 'django-admin startproject' using Django 4.2.9.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
from datetime import timedelta
from pathlib import Path
import os
from dotenv import load_dotenv
#import pandas as pd
import datetime
load_dotenv()
api_key_free = os.environ.get("api_key_free")
api_key = os.environ.get("api_key")
org_id = os.environ.get("org_id")
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
def BasePath():
#/home/mnfbeta/mnf/app
return str(BASE_DIR)
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(os.environ.get("DEBUG", default=0))
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "").split(",")
# Application definition
INSTALLED_APPS = os.environ.get('INSTALLED_APPS').split(',')
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.sites.middleware.CurrentSiteMiddleware',
'allauth.account.middleware.AccountMiddleware',
]
SITE_ID = 1
ROOT_URLCONF = 'MNF.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "build")],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'MNF.wsgi.application'
AUTHENTICATION_BACKENDS = (
'allauth.account.auth_backends.AuthenticationBackend',
'django.contrib.auth.backends.ModelBackend',
)
SOCIALACCOUNT_PROVIDERS = {
"google": {
"SCOPE": [
"profile",
"email",
],
"AUTH_PARAMS": {
"access_type": "offline",
},
},
}
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_VERIFICATION = 'optional'
LOGIN_REDIRECT_URL = '/'
# REQUIRED FOR GMAIL LOGIN
# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# SECURE_SSL_REDIRECT = True
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': os.environ.get('ENGINE'),
'NAME': os.environ.get('DB_NAME'),
'USER':os.environ.get('DB_USER'),
'PASSWORD': os.environ.get('PASSWORD'),
'HOST': os.environ.get('HOST'),
'PORT': os.environ.get('PORT'),
# 'OPTIONS': {
# 'sslmode': 'disable',
# }
}
}
# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = '/static/'
# STATICFILES_DIRS = [BASE_DIR / "static",]
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
print("STATIC_ROOT:",STATIC_ROOT)
SECURE_PROXY_SSL_HEADER =("HTTP_X_FORWARDED_PROTO",'https')
CSRF_TRUSTED_ORIGINS = [os.environ.get('CSRF_TRUSTED_ORIGINS')]
# rest framework
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
"DEFAULT_FILTER_BACKENDS": [
"django_filters.rest_framework.DjangoFilterBackend"
],
'DEFAULT_RENDERER_CLASSES': ['rest_framework.renderers.JSONRenderer']
}
file_path = f"{BASE_DIR}/MNF/Pricing.xlsx"
# rest_framework jwt
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(days=100),
'REFRESH_TOKEN_LIFETIME': timedelta(days=300),
'ROTATE_REFRESH_TOKENS': False,
'BLACKLIST_AFTER_ROTATION': False,
'UPDATE_LAST_LOGIN': False,
'ALGORITHM': 'HS256',
'SIGNING_KEY': SECRET_KEY,
'VERIFYING_KEY': None,
'AUDIENCE': None,
'ISSUER': None,
'JWK_URL': None,
'LEEWAY': 0,
'AUTH_HEADER_TYPES': ('Bearer',),
'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION',
'USER_ID_FIELD': 'id',
'USER_ID_CLAIM': 'user_id',
'USER_AUTHENTICATION_RULE': 'rest_framework_simplejwt.authentication.default_user_authentication_rule',
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
'TOKEN_TYPE_CLAIM': 'token_type',
'TOKEN_USER_CLASS': 'rest_framework_simplejwt.models.TokenUser',
}
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
T_STRIPE_SECRET_KEY = os.environ.get('T_STRIPE_SECRET_KEY')
STRIPE_SECRET_KEY = os.environ.get('STRIPE_SECRET_KEY')
STRIPE_PUBLISHABLE_KEY = os.environ.get('STRIPE_PUBLISHABLE_KEY')
T_STRIPE_PUBLISHABLE_KEY = os.environ.get('T_STRIPE_PUBLISHABLE_KEY')
T_RAZORPAY_KEY_ID = os.environ.get('T_RAZORPAY_KEY_ID')
T_RAZORPAY_KEY_SECRET = os.environ.get('T_RAZORPAY_KEY_SECRET')
RAZORPAY_KEY_ID = os.environ.get('RAZORPAY_KEY_ID')
RAZORPAY_KEY_SECRET = os.environ.get('RAZORPAY_KEY_SECRET')
TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID')
TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN')
TWILIO_PHONE_NUMBER = os.environ.get('TWILIO_PHONE_NUMBER')
MONTHLY_MEMBER = int(os.environ.get('MONTHLY_MEMBER'))
EMPLOY_DISCOUNT = int(os.environ.get('EMPLOY_DISCOUNT'))
IM_DISCOUNT = int(os.environ.get('IM_DISCOUNT'))
YEARLY_MEMBER = int(os.environ.get('YEARLY_MEMBER'))
YEARLY_MEMBER_ADDITIONAL = int(os.environ.get('YEARLY_MEMBER_ADDITIONAL'))
LIFE_MEMBER_ADDITIONAL = int(os.environ.get('LIFE_MEMBER_ADDITIONAL'))
LIFE_MEMBER_YEAR = int(os.environ.get('LIFE_MEMBER_YEAR'))
LIFE_MEMBER = int(os.environ.get('LIFE_MEMBER'))
EARLY_BIRD = int(os.environ.get('EARLY_BIRD'))
GST = int(os.environ.get('GST'))
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_METHODS = [
"DELETE",
"GET",
"OPTIONS",
"PATCH",
"POST",
"PUT",
]
COUNTRY_LIST = {
"AD": "Andorra",
"AE": "United Arab Emirates",
"AF": "Afghanistan",
"AG": "Antigua & Barbuda",
"AI": "Anguilla",
"AL": "Albania",
"AM": "Armenia",
"AN": "Netherlands Antilles",
"AO": "Angola",
"AQ": "Antarctica",
"AR": "Argentina",
"AS": "American Samoa",
"AT": "Austria",
"AU": "Australia",
"AW": "Aruba",
"AZ": "Azerbaijan",
"BA": "Bosnia and Herzegovina",
"BB": "Barbados",
"BD": "Bangladesh",
"BE": "Belgium",
"BF": "Burkina Faso",
"BG": "Bulgaria",
"BH": "Bahrain",
"BI": "Burundi",
"BJ": "Benin",
"BM": "Bermuda",
"BN": "Brunei Darussalam",
"BO": "Bolivia",
"BR": "Brazil",
"BS": "Bahama",
"BT": "Bhutan",
"BU": "Burma (no longer exists)",
"BV": "Bouvet Island",
"BW": "Botswana",
"BY": "Belarus",
"BZ": "Belize",
"CA": "Canada",
"CC": "Cocos (Keeling) Islands",
"CF": "Central African Republic",
"CG": "Congo",
"CH": "Switzerland",
"CI": "Côte D'ivoire (Ivory Coast)",
"CK": "Cook Iislands",
"CL": "Chile",
"CM": "Cameroon",
"CN": "China",
"CO": "Colombia",
"CR": "Costa Rica",
"CS": "Czechoslovakia (no longer exists)",
"CU": "Cuba",
"CV": "Cape Verde",
"CX": "Christmas Island",
"CY": "Cyprus",
"CZ": "Czech Republic",
"DD": "German Democratic Republic (no longer exists)",
"DE": "Germany",
"DJ": "Djibouti",
"DK": "Denmark",
"DM": "Dominica",
"DO": "Dominican Republic",
"DZ": "Algeria",
"EC": "Ecuador",
"EE": "Estonia",
"EG": "Egypt",
"EH": "Western Sahara",
"ER": "Eritrea",
"ES": "Spain",
"ET": "Ethiopia",
"FI": "Finland",
"FJ": "Fiji",
"FK": "Falkland Islands (Malvinas)",
"FM": "Micronesia",
"FO": "Faroe Islands",
"FR": "France",
"FX": "France, Metropolitan",
"GA": "Gabon",
"GB": "United Kingdom (Great Britain)",
"GD": "Grenada",
"GE": "Georgia",
"GF": "French Guiana",
"GH": "Ghana",
"GI": "Gibraltar",
"GL": "Greenland",
"GM": "Gambia",
"GN": "Guinea",
"GP": "Guadeloupe",
"GQ": "Equatorial Guinea",
"GR": "Greece",
"GS": "South Georgia and the South Sandwich Islands",
"GT": "Guatemala",
"GU": "Guam",
"GW": "Guinea-Bissau",
"GY": "Guyana",
"HK": "Hong Kong",
"HM": "Heard & McDonald Islands",
"HN": "Honduras",
"HR": "Croatia",
"HT": "Haiti",
"HU": "Hungary",
"ID": "Indonesia",
"IE": "Ireland",
"IL": "Israel",
"IN": "India",
"IO": "British Indian Ocean Territory",
"IQ": "Iraq",
"IR": "Islamic Republic of Iran",
"IS": "Iceland",
"IT": "Italy",
"JM": "Jamaica",
"JO": "Jordan",
"JP": "Japan",
"KE": "Kenya",
"KG": "Kyrgyzstan",
"KH": "Cambodia",
"KI": "Kiribati",
"KM": "Comoros",
"KN": "St. Kitts and Nevis",
"KP": "Korea, Democratic People's Republic of",
"KR": "Korea, Republic of",
"KW": "Kuwait",
"KY": "Cayman Islands",
"KZ": "Kazakhstan",
"LA": "Lao People's Democratic Republic",
"LB": "Lebanon",
"LC": "Saint Lucia",
"LI": "Liechtenstein",
"LK": "Sri Lanka",
"LR": "Liberia",
"LS": "Lesotho",
"LT": "Lithuania",
"LU": "Luxembourg",
"LV": "Latvia",
"LY": "Libyan Arab Jamahiriya",
"MA": "Morocco",
"MC": "Monaco",
"MD": "Moldova, Republic of",
"MG": "Madagascar",
"MH": "Marshall Islands",
"ML": "Mali",
"MN": "Mongolia",
"MM": "Myanmar",
"MO": "Macau",
"MP": "Northern Mariana Islands",
"MQ": "Martinique",
"MR": "Mauritania",
"MS": "Monserrat",
"MT": "Malta",
"MU": "Mauritius",
"MV": "Maldives",
"MW": "Malawi",
"MX": "Mexico",
"MY": "Malaysia",
"MZ": "Mozambique",
"NA": "Namibia",
"NC": "New Caledonia",
"NE": "Niger",
"NF": "Norfolk Island",
"NG": "Nigeria",
"NI": "Nicaragua",
"NL": "Netherlands",
"NO": "Norway",
"NP": "Nepal",
"NR": "Nauru",
"NT": "Neutral Zone (no longer exists)",
"NU": "Niue",
"NZ": "New Zealand",
"OM": "Oman",
"PA": "Panama",
"PE": "Peru",
"PF": "French Polynesia",
"PG": "Papua New Guinea",
"PH": "Philippines",
"PK": "Pakistan",
"PL": "Poland",
"PM": "St. Pierre & Miquelon",
"PN": "Pitcairn",
"PR": "Puerto Rico",
"PT": "Portugal",
"PW": "Palau",
"PY": "Paraguay",
"QA": "Qatar",
"RE": "Réunion",
"RO": "Romania",
"RU": "Russian Federation",
"RW": "Rwanda",
"SA": "Saudi Arabia",
"SB": "Solomon Islands",
"SC": "Seychelles",
"SD": "Sudan",
"SE": "Sweden",
"SG": "Singapore",
"SH": "St. Helena",
"SI": "Slovenia",
"SJ": "Svalbard & Jan Mayen Islands",
"SK": "Slovakia",
"SL": "Sierra Leone",
"SM": "San Marino",
"SN": "Senegal",
"SO": "Somalia",
"SR": "Suriname",
"ST": "Sao Tome & Principe",
"SU": "Union of Soviet Socialist Republics (no longer exists)",
"SV": "El Salvador",
"SY": "Syrian Arab Republic",
"SZ": "Swaziland",
"TC": "Turks & Caicos Islands",
"TD": "Chad",
"TF": "French Southern Territories",
"TG": "Togo",
"TH": "Thailand",
"TJ": "Tajikistan",
"TK": "Tokelau",
"TM": "Turkmenistan",
"TN": "Tunisia",
"TO": "Tonga",
"TP": "East Timor",
"TR": "Turkey",
"TT": "Trinidad & Tobago",
"TV": "Tuvalu",
"TW": "Taiwan, Province of China",
"TZ": "Tanzania, United Republic of",
"UA": "Ukraine",
"UG": "Uganda",
"UM": "United States Minor Outlying Islands",
"US": "United States of America",
"UY": "Uruguay",
"UZ": "Uzbekistan",
"VA": "Vatican City State (Holy See)",
"VC": "St. Vincent & the Grenadines",
"VE": "Venezuela",
"VG": "British Virgin Islands",
"VI": "United States Virgin Islands",
"VN": "Viet Nam",
"VU": "Vanuatu",
"WF": "Wallis & Futuna Islands",
"WS": "Samoa",
"YD": "Democratic Yemen (no longer exists)",
"YE": "Yemen",
"YT": "Mayotte",
"YU": "Yugoslavia",
"ZA": "South Africa",
"ZM": "Zambia",
"ZR": "Zaire",
"ZW": "Zimbabwe",
"ZZ": "Unknown or unspecified country",
}
languages = {
"hi": "Hindi",
"en": "English",
"ur": "Urdu",
"ar": "Arabic",
"bn": "Bengali",
"kn": "Kannada",
"ta": "Tamil",
"bg": "Bulgarian",
"bn": "Bengali",
"ml": "Malayalam",
"ru": "Russian",
"sr": "Serbian",
"uk": "Ukranian",
"hr": "Croatian",
"ga": "Irish",
"sq": "Albanian",
"mr": "Marathi",
"fa": "Persian",
"te": "Telugu",
"tr": "Turkish",
"hu": "Hungarian",
"it": "Italian",
"ro": "Romanian",
"pa": "Punjabi",
"gu": "Gujarati",
"or": "Oriya",
"zh-CN": "Chinese-Simplified",
"zh-TW": "Chinese-Traditional",
"ne": "Nepali",
"fr": "French",
"es": "Spanish",
"id": "Indonesian",
"el": "Greek",
"ja": "Japanese",
"jv": "Javanese",
"ko": "Korean",
"be": "Belarusian",
"uz": "Uzbek",
"sd": "Sindhi",
"af": "Afrikaans",
"de": "German",
"is": "Icelandic",
"ig": "Igbo",
"la": "Latin",
"pt": "Portugese",
"my": "Myanmar",
"th": "Thai",
"su": "Sundanese",
"lo": "Lao",
"am": "amharic",
"si": "Sinhala",
"az": "Azerbaijani",
"kk": "Kazakh",
"mk": "Macedonian",
"bs": "Bosnian",
"ps": "Pashto",
"mg": "Malagasy",
"ms": "Malay",
"yo": "Yoruba",
"cs": "Czech",
"da": "Danish",
"nl": "Dutch",
"tl": "Tagalog",
"no": "Norwegian",
"sl": "Slovenian",
"sv": " Swedish",
"vi": "Vietnamese",
"cy": "Welsh",
"he": "Hebrew",
"hy": "Armenian",
"km": "Khmer",
"ka": "Georgian",
"mn": "Mongolian",
"ku": "Kurdish",
"ky": "Kyrgyz",
"tk": "Turkmen",
"fi": "Finnish",
"ht": "Haitian Creole",
"haw": "Hawaiian",
"lt": "Lithuanian",
"lb": "Luxembourgish",
"mt": "Maltese",
"pl": "Polish",
"eo": "Esperanto",
"tt": "Tatar",
"ug": "Uyghur",
"ha": "Hausa",
"so": "Somali",
"sw": "Swahili",
"yi": "Yiddish",
"eu": "Basque",
"ca": "Catalan",
"ceb": "Cebuano",
"co": "Corsican",
"et": "Estonian",
"fy": "Frisian",
"gl": "Galician",
"hmn": "Hmong",
"rw": "Kinyarwanda",
"lv": "Latvian",
"mi": "Maori",
"sm": "Samoan",
"gd": "Scots Gaelic",
"st": "Sesotho",
"sn": "Shona",
"sk": "Slovak",
"xh": "Xhosa",
"zu": "Zulu",
}
ISO_INV = {v: k for k, v in COUNTRY_LIST.items()}
ISO_LAN = {v: k for k, v in languages.items()}
# CRONJOBS = [
# lpp task deadline cron job
# ('*/5 * * * *','conversion.cron.delete_empty_files_existing', '>>'+os.path.join(BASE_DIR,'log/debug7.log')),
# translation service down alert
# ('2 */6 * * *', 'conversion.cron.check_transalation_services'),
# ('2 */6 * * *', 'conversion.cron.delete_trasalation_services'),
# # idea mall emails
# ("00 16 * * *", "ideamall.cronmails.mailtoauctionwinner"),
# ("00 16 * * *", "ideamall.cronmails.mailweekleft"),
# ("00 16 * * *", "ideamall.cronmails.mailoneleft"),
# # AutoUpdate conversion Rates
# ("00 8 * * *", "payment.views.custom_conversion_rate"),
# # credits for MM every month
# ("00 00 30 * *", "relationshipmanager.views.credit_monthly_outsession"),
#
# #Institutional Membership
# ('0 0 * * *', 'institutional.views.deactivate_expired_accounts'),
# ('0 0 1 * *', 'institutional.views.deactivate_accounts_with_pending_payments'),
# ('0 0 * * *', 'institutional.views.send_deactivation_reminder_emails'),
#
#
# #auto refund
# ('0 1 * * *','subtitling3.cronjob.subtitlerefund'),
#
# # For reminder mail in messiah
# ('*/5 * * * *','relationshipmanager.cron.remindermail'),
# ]
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
smtp_host = os.environ.get('SMTP_HOST')
smtp_port = int(os.environ.get('SMTP_PORT'))
smtp_username = os.environ.get('SMTP_USERNAME')
smtp_password = os.environ.get('SMTP_PASSWORD')
COUNTRY_KEY = "00000000000000000000000000000000"
def discount_xlsx_reader(filePath:str):
import pandas as pd
discountData = dict()
df = pd.read_excel(filePath, engine='openpyxl',skiprows=101)
for index, row in df.iterrows():
if not pd.isnull(row['discounts']):
if row["limit"] =='yes':
discountData[row['discounts']] ={"limit":True, "data":(row['value'],row['start'],row['end'])}
else:
discountData[row['discounts']] = {"limit":False, "data":row['value']}
return discountData
DISCOUNT = discount_xlsx_reader(f"{BASE_DIR}/MNF/Pricing.xlsx")
def discount_limit_handler(discount:dict) -> int:
current_date = datetime.datetime.now()
if discount["limit"]:
if discount["data"][1].date() <= current_date.date() <= discount["data"][2].date():
return int(discount["data"][0])
else:
return int(0)
else:
return int(discount["data"])
def pricing_data(row_name, column_index):
import pandas as pd
"""
Extract data from a specific cell in an Excel file.
Parameters:
- row_name (str): The name of the row from which to extract data.
- column_index (int): The index of the column from which to extract data.
Returns:
- str: The data in the format [row][column].
"""
try:
# Read the Excel file into a DataFrame
df = pd.read_excel(file_path)
# Find the row index that matches the given row_name
row_index = df[df.iloc[:, 0] == row_name].index[0]
# Extract the data from the specified cell
data = df.iat[row_index, column_index]
# Return the data in the format [row][column]
return f"{data}"
except Exception as e:
return f"An error occurred: {e}"
#nltk dir changes
import nltk
nltk.data.path.append("/home/ubuntu/Conversion_Kitchen_Code/nltk_data")

View File

@ -9,13 +9,134 @@ from django.core.management import call_command
from mnfapp.models import ScriptTranslations
from MNF.settings import BasePath
from conversion.translation.external_conversion import Conversion
from centralisedFileSystem.models import Script, File
from scriptAudit.models import ScriptAuditModel
from scriptAudit.models import States
from utils import filesystem
from scriptAudit.utils import update_audit_status
from scriptAudit.mnf_script_audit import NeutralAudit
from django.core.files.base import ContentFile
from django.contrib.auth import get_user_model
basePath = BasePath()
User = get_user_model()
def background_execution(obj):
obj.convert()
def run_conversion(msg):
body_dict = json.loads(msg.body)
translated_script = ScriptTranslations.objects.get(translation_id=body_dict["translation_id"])
object_key = "INPUT/" + (translated_script.script_link_id.script.name.split("/"))[-1]
local_file_path = "/home/ubuntu/Conversion_Kitchen_Code/kitchen_counter/media/" + translated_script.script_link_id.script.name
s3_client = boto3.client('s3',
aws_access_key_id="AKIAQVLBBGCB45RMLKVW",
aws_secret_access_key="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",
region_name="ap-south-1"
)
s3_client.download_file("conversion-kitchen", object_key, local_file_path)
conversion_params = {
"user": translated_script.user_id,
"file_path": str(basePath) + "/media/" + translated_script.script_link_id.script.name,
"original_script_id": translated_script.script_link_id.script_id,
"translated_script_id": translated_script.translation_id,
"sample_id": body_dict.get('sample_id', None),
"existing_script": body_dict.get('sample_id', None),
"iteration_no": body_dict.get('iteration_no', None),
"juggernaut_pages_deduction": body_dict.get("juggernaut_pages_deduction", None),
"language_set": body_dict.get("language_set", None),
"amount_without_subscrption": body_dict.get("amount_without_subscrption", None)
}
print("reached here")
obj = Conversion(**conversion_params)
# obj.convert()
background_thread = threading.Thread(target=background_execution, args=(obj,))
background_thread.start()
background_thread.join()
msg.delete()
def run_audit(msg):
body_dict = json.loads(msg.body)
user = body_dict.get("user")
s3_url = body_dict.get("s3-file-path")
screenplay_name = body_dict.get("screenplay_name")
author = body_dict.get("author")
language = body_dict.get("language")
script_ext = body_dict.get("script_ext")
script_file_name = body_dict.get("script_file_name")
object_key = "INPUT/" + str(script_file_name)
local_file_path = "/home/ubuntu/Conversion_Kitchen_Code/kitchen_counter/media/audit_counter_files" + script_file_name
s3_client = boto3.client('s3',
aws_access_key_id="AKIAQVLBBGCB45RMLKVW",
aws_secret_access_key="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",
region_name="ap-south-1"
)
s3_client.download_file("conversion-kitchen", object_key, local_file_path)
with open(local_file_path, 'rb') as file:
file_content = file.read()
file = ContentFile(
file_content,
script_file_name,
)
user = User.objects.get(username=user)
# user_id = user.id
result = filesystem.new_screenplay_without_audit_in_background(
user,
author,
screenplay_name,
file,
"script-original",
language,
)
script_id = result.get("script", {}).get("id")
file_to_original = File.objects.get(
script=script_id,
type="script-original"
)
try:
update_audit_status(script_id, States.STARTED)
except:
update_audit_status(script_id, States.FAILURE)
try:
naudit = NeutralAudit(script_id)
naudit.audit()
ScriptAuditModel.objects.update_or_create(
script = Script.objects.get(
id = script_id
),
defaults={"status" : "SUCCESS"}
)
except:
ScriptAuditModel.objects.update_or_create(
script = Script.objects.get(
id = script_id
),
defaults={"status" : "FAILURE"}
)
msg.delete()
class Command(BaseCommand):
help = 'Custom Command to start django server and then start dequeuing from SQS'
@ -59,43 +180,18 @@ class Command(BaseCommand):
MaxNumberOfMessages=5,
WaitTimeSeconds=20,
)
# msg = messages[0]
for msg in messages:
try:
print("Received message: %s: %s", msg.message_id, msg.body)
print(type(msg.body))
body_dict = json.loads(msg.body)
translated_script = ScriptTranslations.objects.get(translation_id=body_dict["translation_id"])
object_key = "INPUT/" + (translated_script.script_link_id.script.name.split("/"))[-1]
local_file_path = "/home/ubuntu/Conversion_Kitchen_Code/kitchen_counter/media/" + translated_script.script_link_id.script.name
s3_client = boto3.client('s3',
aws_access_key_id="AKIAQVLBBGCB45RMLKVW",
aws_secret_access_key="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",
region_name="ap-south-1"
)
s3_client.download_file("conversion-kitchen", object_key, local_file_path)
if body_dict['service_type'] == "conversion":
run_conversion(msg)
elif body_dict['service_type'] == "audit":
conversion_params = {
"user": translated_script.user_id,
"file_path": str(basePath) + "/media/" + translated_script.script_link_id.script.name,
"original_script_id": translated_script.script_link_id.script_id,
"translated_script_id": translated_script.translation_id,
"sample_id": body_dict.get('sample_id', None),
"existing_script": body_dict.get('sample_id', None),
"iteration_no": body_dict.get('iteration_no', None),
"juggernaut_pages_deduction": body_dict.get("juggernaut_pages_deduction", None),
"language_set": body_dict.get("language_set", None),
"amount_without_subscrption": body_dict.get("amount_without_subscrption", None)
}
print("reached here")
obj = Conversion(**conversion_params)
# obj.convert()
background_thread = threading.Thread(target=background_execution, args=(obj,))
background_thread.start()
background_thread.join()
msg.delete()
# return JsonResponse({"sattus":"process started"})
run_audit(msg)
except Exception as error:
print("error execution from queue: %s", error)