Changeset 4372 for trunk/SUBGROUPS.py


Ignore:
Timestamp:
Mar 18, 2020 5:25:22 PM (21 months ago)
Author:
toby
Message:

streamline Post access to web pages; try http before https

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SUBGROUPS.py

    r4365 r4372  
    1616########### SVN repository information ###################
    1717from __future__ import division, print_function
    18 import requests
    1918import numpy as np
    2019import numpy.linalg as nl
    2120import GSASIIspc as G2spc
     21import GSASIIIO as G2IO
    2222import GSASIIpath
    2323GSASIIpath.SetBinaryPath()
    24 submagSite = 'https://www.cryst.ehu.es/cgi-bin/cryst/programs/subgrmag1_general_GSAS.pl?'
     24submagSite = 'http://www.cryst.ehu.es/cgi-bin/cryst/programs/subgrmag1_general_GSAS.pl?'
    2525
    2626def GetNonStdSubgroups(SGData, kvec,star=False,landau=False,maximal=False):
     
    8383        for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]):
    8484            postdict['knm%d%s'%(j,i)] = k
    85     try:
    86         r = requests.get(submagSite,params=postdict)
    87     except:     #ConnectionError?
    88         page = ''
    89         print('connection error - not on internet')
     85    page = G2IO.postURL(submagSite,postdict)
     86    if not page:
     87        print('connection error - not on internet?')
    9088        return None,None
    91     if r.status_code == 200:
    92         print('request OK')
    93         page = r.text
    94         page = page.replace('<font style= "text-decoration: overline;">','<font>-')
    95     else:
    96         page = ''
    97         print('request failed. Reason=',r.reason)
    98         return None,None
    99     r.close()
    100    
     89    page = page.replace('<font style= "text-decoration: overline;">','<font>-')
    10190    result = page.replace('&','\n')
    10291    result = result.split('\n')
     
    211200        for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]):
    212201            postdict['km%d%s'%(j,i)] = k
    213     try:
    214         r = requests.get(submagSite,params=postdict)
    215     except:     #ConnectionError?
    216         page = ''
    217         print('connection error - not on internet')
     202    page = G2IO.postURL(submagSite,postdict)
     203    if not page:
     204        print('connection error - not on internet?')
    218205        return None,None
    219     if r.status_code == 200:
    220         print('request OK')
    221         page = r.text
    222         page = page.replace('<font style= "text-decoration: overline;">','<font>-')
    223     else:
    224         page = ''
    225         print('request failed. Reason=',r.reason)
    226         return None,None
    227     r.close()
    228 
     206    page = page.replace('<font style= "text-decoration: overline;">','<font>-')
    229207    result = page.replace('&','\n')
    230208    result = result.split('\n')
     
    283261    datastr = "sgr={:}&cell={:}&tol={:}&submit=Show".format(
    284262        str(int(spgNum)),cellstr,str(int(tol)))
    285     try:
    286         r = requests.get(psSite,params=datastr)
    287     except:     #ConnectionError?
    288         page = ''
    289         print('connection error - not on internet')
     263    page = G2IO.postURL(psSite,datastr)
     264    if not page:
     265        print('connection error - not on internet?')
    290266        return None
    291     if r.status_code == 200:
    292         print('request OK')
    293         page = r.text
    294         page = page.replace('<font style= "text-decoration: overline;">','<font>-')
    295     else:
    296         page = ''
    297         print('request failed. Reason=',r.reason)
    298         return None
    299     r.close()
     267    page = page.replace('<font style= "text-decoration: overline;">','<font>-')
    300268    return page
    301269
Note: See TracChangeset for help on using the changeset viewer.