Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import os, sys
  2. import requests
  3.  
  4. def getSet(s):
  5.     cur = s.split('"')
  6.     res = list()
  7.     for i in range(0, len(cur)):
  8.         if (cur[i] == 'name'):
  9.             res.append(cur[i + 2])
  10.        
  11.     return res
  12.  
  13. def changeE(s):
  14.     res = ""
  15.     for i in range(0, len(s)):
  16.         if s[i] == 'ั‘':
  17.             res += 'ะต'
  18.         else:
  19.             res += s[i]
  20.     return res
  21.  
  22.  
  23. handle = open("input.txt")
  24. data = handle.read()
  25. words = data.split(' ')
  26.  
  27. url = 'https://sociation.org/ajax/word_associations?word=' + words[0]    
  28. data = {}
  29. res1 = requests.post(url, json=data).text    
  30.  
  31. set1 = getSet(res1)
  32.  
  33. f = open('output.txt', 'w')
  34.  
  35. if words[0] == words[1]:
  36.     for word in set1:
  37.         f.write(changeE(word) + '\n')
  38. else:
  39.     url = 'https://sociation.org/ajax/word_associations?word=' + words[1]    
  40.     data = {}
  41.     res2 = requests.post(url, json=data).text    
  42.  
  43.     set2 = getSet(res2)
  44.  
  45.     for word in set1:
  46.         if word in set2:       
  47.             f.write(changeE(word) + '\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement