Surprise! We've been running on hardware provided by BuyVM for a few months and wanted to show them a little appreciation.
Running a paste site comes with unique challenges, ones that aren't always obvious and hard to control. As such, BuyVM offered us a home where we could worry less about the hosting side of things and focus on maintaining a clean and useful service! Go check them out and show them some love!
Submitted on December 9, 2024 at 06:49 AM
Expires on January 8, 2025 at 06:49 AM (1 week from now)

New Paste 1 (Python)

import os
import re
from urllib.parse import parse_qs
from urllib.request import urlopen
import sys
mentioned = None
env = os.environ
if env['REQUEST_METHOD'] == "POST":
  #qs = parse_qs(env['QUERY_STRING'])
  qs = parse_qs(sys.stdin.read())
 # print(qs)
  if not "source" in qs or not "target" in qs:
    print("Status: 400 Bad Request")
    print()
    print("source or target not found")
    exit()
  if type(qs['source'][0]) != str or type(qs['target'][0]) != str:
    print("Status: 400 Bad Request")
    print()
    print("Invalid source or target")
    exit()
  source = qs['source'][0]
  target = qs['target']
  s = source.split("#:~:text=")
  if len(s[1]) < 1:
    print("Status: 400 Bad Request")
    print("Content-Type: text/plain")
    print()
    print("Bad source")
    exit()
  print(s[0])
  res = urlopen(s[0])
  res = res.read().decode()
  for r in res.split("\n"):
    if r.startswith("#"):
      r = " ".join(r.split())
      match = re.match(r"\#\ (\w*)\ \=\ (.*)",r)
      if match:
        if match.group(1) == "nick":
          mentioned = match.group(2)
    r = r.split("\t")
    if r[0] == s[1] and f"@<doesnm https://doesnm.p.psf.lt/twtxt.txt>" in r[1]:
      
      with open("webmentions.txt","a",encoding="utf8") as f:
        date = datetime.datetime.now().isoformat()
        f.write(date,"\t",f"{mentioned} mentioned you:\u2028{r[1]}\n",end="")
      print("Status: 200 OK")
      print("Content-Type: text/plain")
      print("X-Mentioned: ",mentioned)
      print("X-Mentioned-Content: ",r[1])
      print()
      print("OK")
      exit()
    else:
      print("Status: 400 Bad Request")
      print("Content-Type: text/plain")
      print()
      print("Can't find source twt or there is no mention in it")