PlagueCarrier

clipboard2sauce converter

Jan 11th, 2021
753
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2. import pyperclip
  3. # pip install pyperclip
  4.  
  5.  
  6. TEMPLATE_PATTERN_PAIR = {
  7.     'https://meet.google.com/{0}': r'\w{3}-\w{4}-\w{3}',
  8.     'https://nhentai.net/g/{0}': r'\d{6}'
  9. }
  10.  
  11.  
  12. class CodeSauce:
  13.  
  14.     def __init__(self, template, pattern):
  15.         self.template = template
  16.         self.pattern = re.compile(pattern)
  17.  
  18.     def __call__(self, string):
  19.         match = self.pattern.fullmatch(string)
  20.         if match is not None:
  21.             return self.template.format(match.group(0))
  22.         else:
  23.             return None
  24.  
  25.     def __repr__(self):
  26.         return '<{}, {}>'.format(self.template, self.pattern.pattern)
  27.  
  28.  
  29. class CodeSauceConverter:
  30.  
  31.     def __init__(self):
  32.         self.clip_old = ''
  33.         self.clip = pyperclip.paste()
  34.         self.sauce_list = [CodeSauce(k, v) for k, v in TEMPLATE_PATTERN_PAIR.items()]
  35.         print(self.sauce_list)
  36.  
  37.     def retrieve_sauce(self, code):
  38.         """reads through each pattern"""
  39.         for sauce in self.sauce_list:
  40.             link = sauce(code)
  41.             if link is not None:
  42.                 return link
  43.  
  44.     def loop(self):
  45.         """is blocking"""
  46.         while True:
  47.             if self.clip_old != self.clip:
  48.                 print('Clipboard content changed.')
  49.                 link = self.retrieve_sauce(self.clip)
  50.                 if link is not None:
  51.                     print('Clipboard content mutated.')
  52.                     pyperclip.copy(link)
  53.                     self.clip_old = self.clip = link
  54.                     continue
  55.             self.clip_old, self.clip = self.clip, pyperclip.paste().strip()
  56.  
  57.  
  58. if __name__ == '__main__':
  59.     csc = CodeSauceConverter()
  60.     csc.loop()
  61.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×