Skip to content

Instantly share code, notes, and snippets.

Avatar
😆
I may be slow to respond.

Allwin Raju Allwin12

😆
I may be slow to respond.
View GitHub Profile
View middleware.py
from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
class ProcessRequestMiddleware(MiddlewareMixin):
def process_view(self, request, view_func, *view_args, **view_kwargs):
user = request.user
if user.is_authenticated:
return HttpResponse(status=200)
else:
View unescape_html.py
from html import unescape
escaped_string = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
View html_escape.py
from html import escape
html_string = '''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
View views.py
class SampleView(APIView):
def get(self, request):
user_agent = request.user_agent
browser = user_agent.browser.family
browser_version = user_agent.browser.version_string
os = user_agent.os.family
os_version = user_agent.os.version_string
is_pc = user_agent.is_pc
is_mobile = user_agent.is_mobile
return Response('success')
View views.py
class SampleView(APIView):
def get(self, request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for
else:
ip = request.META.get('REMOTE_ADDR')
return Response({'ip_address': ip})
View views.py
class SampleView(APIView):
def get(self, request):
agent = request.META['HTTP_USER_AGENT']
print(agent)
return Response({'agent': agent})
View views.py
class SampleView(APIView):
def get(self, request):
token = request.META.get('HTTP_AUTHORIZATION')
access_token = token.split()[-1]
print(access_token)
return Response({'token': access_token})
View package_updater.py
import requests
import pkg_resources
from bs4 import BeautifulSoup
from pkg_resources import parse_version
from subprocess import call
base_url = "https://pypi.org/project/"
for pkg in pkg_resources.working_set:
original_version = pkg.version
View graph_whatsapp.py
import re
import matplotlib.pyplot as plt
with open('chat.txt', 'r') as f:
content = f.readlines()
all_dates = []
for line in content:
dates = re.findall(r'[0-9]+/[0-9]+/[0-9]+', line)
if dates:
View captcha.py
from captcha.image import ImageCaptcha
import string
import random
text = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(10))
image = ImageCaptcha()
data = image.generate(text)
image.write(text, 'captcha.png')
You can’t perform that action at this time.